pub trait ChunkTypeSet<const BODY_SIZE: usize = DEFAULT_BODY_SIZE>:
Send
+ Sync
+ 'static {
const BODY_SIZE: usize = BODY_SIZE;
// Required methods
fn supports(type_id: ChunkTypeId) -> bool;
fn deserialize(bytes: &[u8]) -> Result<AnyChunk<BODY_SIZE>>;
fn supported_types() -> &'static [ChunkTypeId];
// Provided method
fn format_supported_types() -> String { ... }
}Expand description
Trait defining a set of supported chunk types with configurable body size.
This trait is implemented by marker types that define which chunk types
a system supports. It enables compile-time configuration of valid chunk types
while providing runtime polymorphism through AnyChunk.
§Design Rationale
This trait uses associated functions (not methods) because the supported types are determined at compile time, not per-instance. This allows:
- Zero-cost type checking at compile time
- Generic programming over chunk type sets
- Runtime dispatch only when necessary (deserialization)
§Example
use nectar_primitives::{ChunkTypeSet, ChunkTypeId, AnyChunk, StandardChunkSet};
// Check if a type is supported
assert!(StandardChunkSet::supports(ChunkTypeId::CONTENT));
assert!(StandardChunkSet::supports(ChunkTypeId::SINGLE_OWNER));
assert!(!StandardChunkSet::supports(ChunkTypeId::custom(200)));
// Get supported types
let types = StandardChunkSet::supported_types();
assert_eq!(types.len(), 2);Provided Associated Constants§
Required Methods§
Sourcefn supports(type_id: ChunkTypeId) -> bool
fn supports(type_id: ChunkTypeId) -> bool
Check if a chunk type ID is supported by this set.
Returns true if chunks with the given type ID can be
deserialized and processed by this set.
Sourcefn deserialize(bytes: &[u8]) -> Result<AnyChunk<BODY_SIZE>>
fn deserialize(bytes: &[u8]) -> Result<AnyChunk<BODY_SIZE>>
Deserialize bytes into the appropriate chunk type.
The first byte of the input should be the chunk type ID. Returns an error if the type is not supported or deserialization fails.
§Errors
Returns ChunkError::UnsupportedType if the type ID is not in this set.
May return other errors from the underlying chunk deserialization.
Sourcefn supported_types() -> &'static [ChunkTypeId]
fn supported_types() -> &'static [ChunkTypeId]
Get the list of all supported type IDs.
This returns a static slice for efficiency in const contexts.
Provided Methods§
Sourcefn format_supported_types() -> String
fn format_supported_types() -> String
Format the supported chunk types as a human-readable string.
Returns a comma-separated list with abbreviations and hex codes, e.g., “CAC (0x00), SOC (0x01)”.
§Example
use nectar_primitives::{ChunkTypeSet, StandardChunkSet, DEFAULT_BODY_SIZE};
let formatted = <StandardChunkSet as ChunkTypeSet<DEFAULT_BODY_SIZE>>::format_supported_types();
assert!(formatted.contains("CAC"));
assert!(formatted.contains("SOC"));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".