Skip to content

Commit

Permalink
[357] Sealing access::{Guard, WritePtr}
Browse files Browse the repository at this point in the history
  • Loading branch information
halzy committed Jun 26, 2020
1 parent a68b530 commit a2c6e1f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions gdnative-core/src/core_types/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,28 @@ where
}

/// Trait for array access guards
#[doc(hidden)]
///
/// This trait is sealed.
#[allow(clippy::len_without_is_empty)]
pub unsafe trait Guard: Drop {
pub unsafe trait Guard: Drop + private::Sealed {
type Target;
fn len(&self) -> usize;
fn read_ptr(&self) -> *const Self::Target;
}

/// Marker trait for write access guards
#[doc(hidden)]
pub unsafe trait WritePtr: Guard {}
///
/// This trait is sealed and has no public members.
pub unsafe trait WritePtr: Guard + private::Sealed {}

pub(crate) mod private {
use crate::core_types::typed_array::Element;

pub trait Sealed {}

impl<'a, T: Element> Sealed for crate::core_types::typed_array::ReadGuard<'a, T> {}
impl<'a, T: Element> Sealed for crate::core_types::typed_array::WriteGuard<'a, T> {}
}

impl<G: Guard> MaybeUnaligned<G> {
#[inline]
Expand Down Expand Up @@ -217,6 +228,8 @@ mod tests {
len: usize,
}

impl<T> crate::core_types::access::private::Sealed for PtrGuard<T> {}

impl<T> Drop for PtrGuard<T> {
fn drop(&mut self) {}
}
Expand Down

0 comments on commit a2c6e1f

Please sign in to comment.