pub enum SyncMode {
ProducerSynced,
Event,
ConsumerStream,
}Expand description
Describes how the producer–consumer memory ordering guarantee is established for a buffer.
The sync_mode field in the binary buffer handle is a single uint8 at
wire offset 13. This enum is the typed representation of that byte; use
SyncMode::from_byte to parse and SyncMode::to_byte to serialize.
CPU buffers (device_tag == 0x00) MUST use SyncMode::ProducerSynced;
BufferHandle::new enforces this and returns Error::InvalidSyncMode
if any other mode is combined with DeviceTag::Cpu.
| Wire value | Variant |
|---|---|
0x00 | ProducerSynced |
0x01 | Event |
0x02 | ConsumerStream |
0x03–0xFF | reserved / permanently invalid → Error::InvalidSyncMode |
See docs/spec/buffer-protocol.md § Synchronization Mode and ADR-018.
§Examples
use hurray_core::{SyncMode, Error};
let mode = SyncMode::from_byte(0x00).unwrap();
assert_eq!(mode, SyncMode::ProducerSynced);
assert_eq!(mode.to_byte(), 0x00);
assert_eq!(mode.to_string(), "producer_synced");
let event = SyncMode::from_byte(0x01).unwrap();
assert_eq!(event, SyncMode::Event);
assert!(matches!(SyncMode::from_byte(0x03), Err(Error::InvalidSyncMode(0x03))));
assert!(matches!(SyncMode::from_byte(0xFF), Err(Error::InvalidSyncMode(0xFF))));Variants§
ProducerSynced
Producer has issued a host-side wait; consumer may access on any stream.
This is the only valid mode for CPU buffers (device_tag == 0x00).
Wire byte 0x00.
Event
Producer recorded a device event; consumer must wait on it via the C ABI.
Wire byte 0x01.
ConsumerStream
Consumer declared a target stream; producer ordered it device-side.
Wire byte 0x02.
Implementations§
Source§impl SyncMode
impl SyncMode
Sourcepub fn from_byte(b: u8) -> Result<Self>
pub fn from_byte(b: u8) -> Result<Self>
Parses a SyncMode from its one-byte wire representation.
§Errors
Error::InvalidSyncMode— byte is0x03–0xFF(reserved or permanently invalid).
§Examples
use hurray_core::{SyncMode, Error};
assert_eq!(SyncMode::from_byte(0x00).unwrap(), SyncMode::ProducerSynced);
assert_eq!(SyncMode::from_byte(0x01).unwrap(), SyncMode::Event);
assert_eq!(SyncMode::from_byte(0x02).unwrap(), SyncMode::ConsumerStream);
assert!(matches!(SyncMode::from_byte(0x03), Err(Error::InvalidSyncMode(0x03))));
assert!(matches!(SyncMode::from_byte(0xFE), Err(Error::InvalidSyncMode(0xFE))));
assert!(matches!(SyncMode::from_byte(0xFF), Err(Error::InvalidSyncMode(0xFF))));Trait Implementations§
impl Copy for SyncMode
Source§impl Display for SyncMode
impl Display for SyncMode
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the sync mode as a human-readable lowercase string.
§Examples
use hurray_core::SyncMode;
assert_eq!(SyncMode::ProducerSynced.to_string(), "producer_synced");
assert_eq!(SyncMode::Event.to_string(), "event");
assert_eq!(SyncMode::ConsumerStream.to_string(), "consumer_stream");