xous: don't allow mutable slices from immutable ranges

If a MemoryRange is defined as immutable, don't allow `as_mut_slice()`
to be called. This is an API-breaking change.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-08-05 16:58:20 +08:00
parent 66005b8b6f
commit 5fcfd6a2aa

View file

@ -703,7 +703,7 @@ impl MemoryRange {
/// For example, if the allocation is 4096 bytes, then the resulting
/// `&[u8]` would have 4096 elements, `&[u16]` would have 2048, and
/// `&[u32]` would have 1024. Values are rounded down.
pub fn as_slice_mut<T>(&self) -> &mut [T] {
pub fn as_slice_mut<T>(&mut self) -> &mut [T] {
// This is safe because the pointer and length are guaranteed to
// be valid, as long as the user hasn't already called `as_ptr()`
// and done something unsound with the resulting pointer.