#[non_exhaustive]pub enum CompositionRule {
Partition,
Overlay(CombineOp),
Group,
}Expand description
The composition rule declared by a composite head (composition_rule wire field).
Models combine_op as part of the rule (rather than a sibling field) so that
illegal combinations — e.g. a non-zero combine_op on a partition or group head —
are unrepresentable in this type: only CompositionRule::Overlay carries a
CombineOp at all.
§Examples
use hurray_core::layout::{CombineOp, CompositionRule};
let partition = CompositionRule::Partition;
assert_eq!(partition.rule_byte(), 0x01);
assert_eq!(partition.combine_op_byte(), 0x00);
let overlay = CompositionRule::Overlay(CombineOp::Add);
assert_eq!(overlay.rule_byte(), 0x02);
assert_eq!(overlay.combine_op_byte(), 0x02);
assert_eq!(
CompositionRule::from_wire(0x02, 0x01).unwrap(),
CompositionRule::Overlay(CombineOp::Replace),
);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Partition
Exact-cover, non-overlapping tiling of the head’s index space. Wire 0x01.
Overlay(CombineOp)
A base spanning the whole index space plus scattered corrections. Wire 0x02.
Group
Independent tensors under one head identity; no spatial semantics. Wire 0x03.
Implementations§
Source§impl CompositionRule
impl CompositionRule
Sourcepub fn rule_byte(&self) -> u8
pub fn rule_byte(&self) -> u8
Returns the wire composition_rule byte for this rule.
§Examples
use hurray_core::layout::{CombineOp, CompositionRule};
assert_eq!(CompositionRule::Group.rule_byte(), 0x03);
assert_eq!(CompositionRule::Overlay(CombineOp::Replace).rule_byte(), 0x02);Sourcepub fn combine_op_byte(&self) -> u8
pub fn combine_op_byte(&self) -> u8
Returns the wire combine_op byte: 0x00 unless this is
CompositionRule::Overlay, in which case it is the wrapped
CombineOp’s wire byte.
§Examples
use hurray_core::layout::CompositionRule;
assert_eq!(CompositionRule::Partition.combine_op_byte(), 0x00);Sourcepub fn from_wire(rule: u8, combine_op: u8) -> Result<Self>
pub fn from_wire(rule: u8, combine_op: u8) -> Result<Self>
Constructs a CompositionRule from its wire composition_rule and
combine_op bytes, validating both per spec § Head Layout-Specific Fields.
The private-range rejection (0xF0–0xFE) mirrors
crate::layout::is_private_tag’s layout-tag convention, for consistency
across the crate’s wire-byte taxonomies.
§Errors
Error::InvalidCompositionRule—rule == 0xFF(permanently invalid).Error::ReservedCompositionRule—rule == 0x00or in0x04..=0xEF.Error::PrivateCompositionRule—ruleis in0xF0..=0xFE.Error::InvalidCombineOp—combine_opis not0x00for partition/group, or not0x01/0x02for overlay.
§Examples
use hurray_core::{Error, layout::{CombineOp, CompositionRule}};
assert_eq!(CompositionRule::from_wire(0x01, 0x00).unwrap(), CompositionRule::Partition);
assert_eq!(CompositionRule::from_wire(0x03, 0x00).unwrap(), CompositionRule::Group);
assert_eq!(
CompositionRule::from_wire(0x02, 0x02).unwrap(),
CompositionRule::Overlay(CombineOp::Add),
);
// 0x00 is reserved (not the permanently-invalid sentinel — that's 0xFF).
assert!(matches!(
CompositionRule::from_wire(0x00, 0x00),
Err(Error::ReservedCompositionRule(0x00))
));
assert!(matches!(
CompositionRule::from_wire(0xFF, 0x00),
Err(Error::InvalidCompositionRule(0xFF))
));
// A non-zero combine_op on a partition head is rejected.
assert!(CompositionRule::from_wire(0x01, 0x01).is_err());
// combine_op outside {0x01, 0x02} on an overlay head is rejected.
assert!(CompositionRule::from_wire(0x02, 0x03).is_err());Trait Implementations§
Source§impl Clone for CompositionRule
impl Clone for CompositionRule
Source§fn clone(&self) -> CompositionRule
fn clone(&self) -> CompositionRule
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompositionRule
impl Debug for CompositionRule
impl Eq for CompositionRule
Source§impl Hash for CompositionRule
impl Hash for CompositionRule
Source§impl PartialEq for CompositionRule
impl PartialEq for CompositionRule
Source§fn eq(&self, other: &CompositionRule) -> bool
fn eq(&self, other: &CompositionRule) -> bool
self and other values to be equal, and is used by ==.