Lines Matching defs:T

18 /// This is similar to a [`crate::alloc::kvec::Vec<Option<T>>`], but more efficient when there are
24 /// `XA_ZERO_ENTRY` or came from `T::into_foreign`.
56 pub struct XArray<T: ForeignOwnable> {
59 _p: PhantomData<T>,
63 impl<T: ForeignOwnable> PinnedDrop for XArray<T> {
67 // SAFETY: `ptr` came from `T::into_foreign`.
71 drop(unsafe { T::from_foreign(ptr) })
87 impl<T: ForeignOwnable> XArray<T> {
122 pub fn try_lock(&self) -> Option<Guard<'_, T>> {
135 pub fn lock(&self) -> Guard<'_, T> {
150 pub struct Guard<'a, T: ForeignOwnable> {
151 xa: &'a XArray<T>,
155 impl<T: ForeignOwnable> Drop for Guard<'_, T> {
167 pub struct StoreError<T> {
171 pub value: T,
174 impl<T> From<StoreError<T>> for Error {
176 fn from(value: StoreError<T>) -> Self {
181 impl<'a, T: ForeignOwnable> Guard<'a, T> {
193 pub fn get(&self, index: usize) -> Option<T::Borrowed<'_>> {
195 // SAFETY: `ptr` came from `T::into_foreign`.
196 unsafe { T::borrow(ptr.as_ptr()) }
201 pub fn get_mut(&mut self, index: usize) -> Option<T::BorrowedMut<'_>> {
203 // SAFETY: `ptr` came from `T::into_foreign`.
204 unsafe { T::borrow_mut(ptr.as_ptr()) }
209 pub fn remove(&mut self, index: usize) -> Option<T> {
215 // - `ptr` is either NULL or came from `T::into_foreign`.
216 // - `&mut self` guarantees that the lifetimes of [`T::Borrowed`] and [`T::BorrowedMut`]
218 unsafe { T::try_from_foreign(ptr) }
231 value: T,
233 ) -> Result<Option<T>, StoreError<T>> {
235 T::FOREIGN_ALIGN >= 4,
246 // INVARIANT: `new` came from `T::into_foreign`.
254 // SAFETY: `new` came from `T::into_foreign` and `__xa_store` does not take
256 let value = unsafe { T::from_foreign(new) };
263 // SAFETY: `ptr` is either NULL or came from `T::into_foreign`.
267 Ok(unsafe { T::try_from_foreign(old) })
272 // SAFETY: `XArray<T>` has no shared mutable state so it is `Send` iff `T` is `Send`.
273 unsafe impl<T: ForeignOwnable + Send> Send for XArray<T> {}
275 // SAFETY: `XArray<T>` serialises the interior mutability it provides so it is `Sync` iff `T` is
277 unsafe impl<T: ForeignOwnable + Send> Sync for XArray<T> {}