Skip to content

Commit

Permalink
seal PrimType trait
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Jul 26, 2023
1 parent fdec718 commit dd7eb0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/types/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,22 @@ impl TypeTag {
}

/// Trait of primitive types (SimpleType or ClassicType).
pub trait PrimType: std::fmt::Debug + Clone + 'static {
pub trait PrimType: private::Sealed + std::fmt::Debug + Clone + 'static {
// may be updated with functions in future for necessary shared functionality
// across ClassicType, SimpleType and HashableType.
// Currently used to constrain Container<T>
/// Tells us the [TypeTag] of the type represented by the receiver.
fn tag(&self) -> TypeTag;
}

// sealed trait pattern to prevent users extending PrimType
mod private {
use super::{ClassicType, HashableType, SimpleType};
pub trait Sealed {}
impl Sealed for SimpleType {}
impl Sealed for ClassicType {}
impl Sealed for HashableType {}
}
/// A type that represents a container of other types.
///
/// For algebraic types Sum, Tuple if one element of type row is linear, the
Expand Down
1 change: 1 addition & 0 deletions src/types/simple/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub(crate) enum SerSimpleType {
},
}

impl super::private::Sealed for SerSimpleType {}
impl PrimType for SerSimpleType {
fn tag(&self) -> TypeTag {
unimplemented!()
Expand Down

0 comments on commit dd7eb0c

Please sign in to comment.