Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: Enhance Bound Enum with Utility Methods and Refactor Storable Trait #142

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Changes from 6 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
21 changes: 21 additions & 0 deletions src/storable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ pub enum Bound {
},
}

impl Bound {
b3hr4d marked this conversation as resolved.
Show resolved Hide resolved
/// Returns the maximum size of the type if bounded, panics if unbounded.
pub const fn max_size(&self) -> u32 {
if let Bound::Bounded { max_size, .. } = self {
*max_size
} else {
panic!("Cannot get max size of unbounded type.");
}
}

/// Returns true if the type is fixed in size, false otherwise.
/// Panics if unbounded.
b3hr4d marked this conversation as resolved.
Show resolved Hide resolved
pub const fn is_fixed_size(&self) -> bool {
if let Bound::Bounded { is_fixed_size, .. } = self {
*is_fixed_size
} else {
false
}
}
}

/// Variable-size, but limited in capacity byte array.
#[derive(Eq, Copy, Clone)]
pub struct Blob<const N: usize> {
Expand Down
Loading