Mark brand types as repr(transparent) to try to ensure safety.

This commit is contained in:
2025-01-22 14:13:58 -05:00
parent da5f680939
commit 9ee7882b1f

View File

@@ -38,6 +38,7 @@ pub trait BrandState: Copy + fmt::Debug + Eq + Hash + Ord + sealed::Sealed {}
/// Zero-sized marker type that indicates a graph or graph handle is in the open
/// state. See [`Graph::open`].
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Open<'id>(PhantomData<*mut &'id ()>);
impl<'id> BrandState for Open<'id> {}
unsafe impl<'id> Send for Open<'id> {}
@@ -51,6 +52,7 @@ unsafe impl<'id> Sync for Open<'id> {}
/// around without having to stay within the bounds of a single call to
/// `Graph::open`. See [`Graph::open`] (and [`Graph::closed`]).
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Closed;
impl BrandState for Closed {}