Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seal PrimType trait #296

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: sealed::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 sealed {
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::sealed::Sealed for SerSimpleType {}
impl PrimType for SerSimpleType {
fn tag(&self) -> TypeTag {
unimplemented!()
Expand Down