Skip to main content

State

Trait State 

Source
pub trait State<T, ReplyParams>: Clone
where T: Into<ReplyParams> + Clone + Debug, ReplyParams: Clone + Send + 'static + Debug,
{ type Stream: Stream<Item = Reply<ReplyParams>>; // Required methods fn new(value: T) -> Self; fn set(&mut self, value: T) -> impl Future<Output = ()> + Send; fn get(&self) -> T; fn stream(&self) -> Self::Stream; fn stream_once(&self) -> Self::Stream; }
Expand description

Trait for a notified state that tracks a value and broadcasts changes.

This is useful for implementing service properties that notify subscribers when they change.

Required Associated Types§

Source

type Stream: Stream<Item = Reply<ReplyParams>>

The stream type returned by stream.

Required Methods§

Source

fn new(value: T) -> Self

Create a new notified state with the given initial value.

Source

fn set(&mut self, value: T) -> impl Future<Output = ()> + Send

Set the value and notify all listeners.

Source

fn get(&self) -> T

Get the current value.

Source

fn stream(&self) -> Self::Stream

Get a stream of replies for this state.

Source

fn stream_once(&self) -> Self::Stream

Get a stream of replies for this state, that only yields one reply: the current state.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, ReplyParams> State<T, ReplyParams> for State<T, ReplyParams>
where T: Into<ReplyParams> + Clone + Debug + Send, ReplyParams: Clone + Send + 'static + Debug,

Source§

type Stream = Stream<ReplyParams>