Attempts to borrow a raw guest slice of memory pointed to by `ptr`. This method will attempt to return a raw pointer into guest memory. This can only be done for `Unshared` memories. A `Shared` memory will return `Ok(None)` here. # Errors An error is returned if `ptr` is out of bounds, misaligned, or otherwise not valid to read from.
(&self, ptr: GuestPtr<[u8]>)
| 129 | /// An error is returned if `ptr` is out of bounds, misaligned, or otherwise |
| 130 | /// not valid to read from. |
| 131 | pub fn as_slice(&self, ptr: GuestPtr<[u8]>) -> Result<Option<&[u8]>, GuestError> { |
| 132 | let range = self.validate_range::<u8>(ptr.pointer.0, ptr.pointer.1)?; |
| 133 | match self { |
| 134 | GuestMemory::Unshared(slice) => Ok(Some(&slice[range])), |
| 135 | GuestMemory::Shared(_) => Ok(None), |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /// Same as [`GuestMemory::as_slice`] but for strings. |
| 140 | pub fn as_str(&self, ptr: GuestPtr<str>) -> Result<Option<&str>, GuestError> { |