Skip to content

Commit

Permalink
schema: add constant type constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Nov 14, 2023
1 parent a99b1ce commit bff1cb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/schema/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::LIB_NAME_RGB;
)]
pub struct AssignmentType(u16);
impl AssignmentType {
pub const fn with(ty: u16) -> Self { Self(ty) }
#[inline]
pub fn to_le_bytes(&self) -> [u8; 2] { self.0.to_le_bytes() }
}
Expand All @@ -54,6 +55,9 @@ impl AssignmentType {
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct ValencyType(u16);
impl ValencyType {
pub const fn with(ty: u16) -> Self { Self(ty) }
}

pub type GlobalSchema = TinyOrdMap<GlobalStateType, Occurrences>;
pub type ValencySchema = TinyOrdSet<ValencyType>;
Expand Down
9 changes: 9 additions & 0 deletions src/schema/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ use crate::{Ffv, GlobalStateSchema, Occurrences, LIB_NAME_RGB};
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct GlobalStateType(u16);
impl GlobalStateType {
pub const fn with(ty: u16) -> Self { Self(ty) }
}

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From, Display)]
#[wrapper(FromStr, LowerHex, UpperHex)]
Expand All @@ -61,6 +64,9 @@ pub struct GlobalStateType(u16);
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct ExtensionType(u16);
impl ExtensionType {
pub const fn with(ty: u16) -> Self { Self(ty) }
}

#[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From, Display)]
#[wrapper(FromStr, LowerHex, UpperHex)]
Expand All @@ -74,6 +80,9 @@ pub struct ExtensionType(u16);
serde(crate = "serde_crate", rename_all = "camelCase")
)]
pub struct TransitionType(u16);
impl TransitionType {
pub const fn with(ty: u16) -> Self { Self(ty) }
}

impl TransitionType {
pub const BLANK: Self = TransitionType(u16::MAX);
Expand Down

0 comments on commit bff1cb4

Please sign in to comment.