Allow creation of GuestPtr<[T]> from GuestPtr<T> and length (#39)

* add GuestPtr::as_array method

* wasi test: show with type signatures we have achieved the desired api
This commit is contained in:
Pat Hickey
2020-03-06 17:45:09 -08:00
committed by GitHub
parent 6e3ec6a96d
commit 06bcac3e43
2 changed files with 30 additions and 3 deletions

View File

@@ -306,7 +306,7 @@ impl<'a, T: ?Sized + Pointee> GuestPtr<'a, T> {
T::read(self)
}
/// Safely write a valud to this pointer.
/// Safely write a value to this pointer.
///
/// This method, like [`GuestPtr::read`], is pretty crucial for the safe
/// operation of this crate. All the same reasons apply though for why this
@@ -342,6 +342,15 @@ impl<'a, T: ?Sized + Pointee> GuestPtr<'a, T> {
};
Ok(GuestPtr::new(self.mem, offset))
}
/// Returns a `GuestPtr` for an array of `T`s using this pointer as the
/// base.
pub fn as_array(&self, elems: u32) -> GuestPtr<'a, [T]>
where
T: GuestType<'a> + Pointee<Pointer = u32>,
{
GuestPtr::new(self.mem, (self.pointer, elems))
}
}
impl<'a, T> GuestPtr<'a, [T]> {