xous: add send() to String

This call can be used to send a string to a Server.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-11-01 16:28:47 +08:00
parent 7ab2338ff3
commit 08fb5e0a0b

View file

@ -46,7 +46,7 @@ impl<'a> String<'a> {
/// 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> {
pub fn lend(&self, connection: CID, id: crate::MessageId) -> core::result::Result<Result, Error> {
let memory_range =
MemoryRange::new(self.raw_slice.as_ptr() as _, self.raw_slice.len()).unwrap();
let msg = MemoryMessage {
@ -58,6 +58,19 @@ impl<'a> String<'a> {
send_message(connection, Message::Borrow(msg))
}
/// Move this string from the client into the server.
pub fn send(self, connection: CID, id: crate::MessageId) -> core::result::Result<Result, Error> {
let memory_range =
MemoryRange::new(self.raw_slice.as_ptr() as _, self.raw_slice.len()).unwrap();
let msg = MemoryMessage {
id,
buf: memory_range,
offset: None,
valid: MemorySize::new(self.len).map(Some).unwrap_or(None),
};
send_message(connection, Message::Move(msg))
}
/// Clear the contents of this String and set the length to 0
pub fn clear(&mut self) {
self.len = 0;