Skip to main content

ReactiveStateV0

Enum ReactiveStateV0 

Source
#[non_exhaustive]
pub enum ReactiveStateV0 { Available(ReactiveValueV0), Unavailable(ReactiveUnavailableV0), }
Expand description

The complete state of one node.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.

Implementations§

Source§

impl ReactiveStateV0

Source

pub fn available(value: ReactiveValueV0) -> Self

Examples found in repository?
examples/performance_envelope.rs (line 19)
16fn project_counter(state: &ReactiveStateV0) -> ReactiveStateV0 {
17    match state {
18        ReactiveStateV0::Available(ReactiveValueV0::Counter(value)) => {
19            ReactiveStateV0::available(ReactiveValueV0::Counter(value.rotate_left(7)))
20        }
21        _ => ReactiveStateV0::unavailable("counterRequired", "expected a counter deposit"),
22    }
23}
24
25fn settle(engine: &mut ReactiveEngineV0) -> Result<(), Box<dyn Error>> {
26    loop {
27        if matches!(
28            engine.stabilize_step(4_096)?,
29            StabilizeStatusV0::Settled { .. }
30        ) {
31            return Ok(());
32        }
33    }
34}
35
36fn graph() -> Result<(ReactiveEngineV0, Vec<ReactiveNodeIdV0>), Box<dyn Error>> {
37    let policy = ChangePolicyV0::exact("performanceSemanticValue");
38    let mut graph = ReactiveGraphBuilderV0::new();
39    let mut inputs = Vec::with_capacity(INPUT_COUNT);
40    let mut projections = Vec::with_capacity(INPUT_COUNT);
41    for index in 0..INPUT_COUNT {
42        let input = graph.add_input(
43            ReactiveStateV0::available(ReactiveValueV0::Counter(index as u64)),
44            policy,
45        );
46        inputs.push(input);
47        projections.push((
48            format!("projection-{index}"),
49            graph.add_map(input, project_counter, policy),
50        ));
51    }
52    let fold = graph.add_delta_fold(projections, policy)?;
53    let boundary = graph.add_effect_boundary(fold, "performance-observation", policy);
54    let mut engine = graph.build()?;
55    engine.observe(boundary)?;
56    settle(&mut engine)?;
57    engine.drain_effect_receipts();
58    Ok((engine, inputs))
59}
60
61fn measure(changes_input: bool) -> Result<Vec<Duration>, Box<dyn Error>> {
62    let (mut engine, inputs) = graph()?;
63    let mut samples = Vec::with_capacity(EVENT_COUNT);
64    for event in 0..EVENT_COUNT {
65        let index = event % INPUT_COUNT;
66        let value = if changes_input {
67            (index + event + 1) as u64
68        } else {
69            index as u64
70        };
71        let started = Instant::now();
72        engine.deposit(
73            inputs[index],
74            ReactiveStateV0::available(ReactiveValueV0::Counter(value)),
75        )?;
76        settle(&mut engine)?;
77        engine.drain_effect_receipts();
78        samples.push(started.elapsed());
79    }
80    Ok(samples)
81}
Source

pub fn unavailable(code: impl Into<String>, detail: impl Into<String>) -> Self

Examples found in repository?
examples/performance_envelope.rs (line 21)
16fn project_counter(state: &ReactiveStateV0) -> ReactiveStateV0 {
17    match state {
18        ReactiveStateV0::Available(ReactiveValueV0::Counter(value)) => {
19            ReactiveStateV0::available(ReactiveValueV0::Counter(value.rotate_left(7)))
20        }
21        _ => ReactiveStateV0::unavailable("counterRequired", "expected a counter deposit"),
22    }
23}

Trait Implementations§

Source§

impl Clone for ReactiveStateV0

Source§

fn clone(&self) -> ReactiveStateV0

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 Debug for ReactiveStateV0

Source§

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

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

impl Eq for ReactiveStateV0

Source§

impl Ord for ReactiveStateV0

Source§

fn cmp(&self, other: &ReactiveStateV0) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for ReactiveStateV0

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for ReactiveStateV0

Source§

fn partial_cmp(&self, other: &ReactiveStateV0) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for ReactiveStateV0

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.