Skip to main content

SyncMode

Enum SyncMode 

Source
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 valueVariant
0x00ProducerSynced
0x01Event
0x02ConsumerStream
0x03–0xFFreserved / 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

Source

pub fn from_byte(b: u8) -> Result<Self>

Parses a SyncMode from its one-byte wire representation.

§Errors
§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))));
Source

pub fn to_byte(self) -> u8

Returns the one-byte wire representation of this sync mode.

§Examples
use hurray_core::SyncMode;

assert_eq!(SyncMode::ProducerSynced.to_byte(), 0x00);
assert_eq!(SyncMode::Event.to_byte(), 0x01);
assert_eq!(SyncMode::ConsumerStream.to_byte(), 0x02);

Trait Implementations§

Source§

impl Clone for SyncMode

Source§

fn clone(&self) -> SyncMode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SyncMode

Source§

impl Debug for SyncMode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SyncMode

Source§

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");
Source§

impl Eq for SyncMode

Source§

impl Hash for SyncMode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SyncMode

Source§

fn eq(&self, other: &SyncMode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SyncMode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.