mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
xous: String: add from_message() as an initializer
Allow creating a `String` from a `MemoryMessage`. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
d76832dada
commit
4650e865fb
1 changed files with 19 additions and 0 deletions
|
|
@ -25,6 +25,25 @@ impl<'a> String<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.len
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len == 0
|
||||
}
|
||||
|
||||
/// Convert a `MemoryMessage` into a `String`
|
||||
pub fn from_message(message: &'a mut MemoryMessage) -> core::result::Result<String<'a>, core::str::Utf8Error> {
|
||||
let raw_slice = unsafe { core::slice::from_raw_parts_mut(message.buf.as_mut_ptr(), message.buf.len()) };
|
||||
let starting_length = message.valid.map(|x| x.get()).unwrap_or(0);
|
||||
Ok(String {
|
||||
raw_slice,
|
||||
s: core::str::from_utf8(unsafe { core::slice::from_raw_parts(message.buf.as_ptr(), starting_length) })?,
|
||||
len: 0,
|
||||
})
|
||||
}
|
||||
|
||||
/// Perform an immutable lend of this String to the specified server.
|
||||
/// This function will block until the server returns.
|
||||
pub fn lend(&self, connection: CID, id: usize) -> core::result::Result<Result, Error> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue