xous: definitions: add memory() call to Result

This is used to get attached Memory from a Result, if any.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-10-30 10:13:09 +08:00
parent 8115c2e7cf
commit 39c9ef30b7

View file

@ -306,6 +306,15 @@ impl Message {
}
}
pub fn memory(&self) -> Option<&MemoryRange> {
match self {
Message::MutableBorrow(mem) | Message::Borrow(mem) | Message::Move(mem) => {
Some(&mem.buf)
}
Message::BlockingScalar(_) | Message::Scalar(_) => None,
}
}
pub fn message_type(&self) -> usize {
match *self {
Message::MutableBorrow(_) => 1,
@ -369,10 +378,7 @@ impl MemoryRange {
addr != 0,
"tried to construct a memory range with a null pointer"
);
assert!(
size != 0,
"tried to construct a zero-length memory range"
);
assert!(size != 0, "tried to construct a zero-length memory range");
Ok(MemoryRange {
addr: MemoryAddress::new(addr).ok_or(Error::BadAddress)?,
size: MemorySize::new(size).ok_or(Error::BadAddress)?,
@ -580,7 +586,6 @@ impl Result {
}
}
/// If the Result has memory attached to it, return the memory
pub fn memory(&self) -> Option<MemoryRange> {
match self {