Struct Stream

Source
pub struct Stream<T: RpcType + Send> { /* private fields */ }
Expand description

A streaming procedure call.

Stream<T> is created by calling any procedure with the _stream() suffix. This will start the stream automatically.

This type provides access to the procedure’s results of type T via get. Results are pushed by the server at the rate selected by set_rate. And consumers may block until a stream’s value has changed with wait.

The stream will attempt to remove itself when dropped. Otherwise the server will remove remaining streams when the client disconnects.

Implementations§

Source§

impl<T: RpcType + Send> Stream<T>

Source

pub fn set_rate(&self, hz: f32) -> Result<(), RpcError>

Set the update rate for this streaming procedure.

Examples found in repository?
examples/streams.rs (line 14)
7fn main() -> Result<(), Box<dyn Error>> {
8    let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10    let space_center = SpaceCenter::new(client.clone());
11
12    // Set up a stream.
13    let ut_stream = space_center.get_ut_stream()?;
14    ut_stream.set_rate(1f32)?;
15
16    // Wait for updates, and print the current value.
17    for _ in 0..10 {
18        ut_stream.wait();
19        println!("It's {} o'clock", ut_stream.get()?);
20    }
21
22    Ok(())
23}
Source

pub fn get(&self) -> Result<T, RpcError>

Retrieve the current result received for this procedure. This value is not guaranteed to have changed since the last call to get. Use wait to block until the value has changed.

Examples found in repository?
examples/streams.rs (line 19)
7fn main() -> Result<(), Box<dyn Error>> {
8    let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10    let space_center = SpaceCenter::new(client.clone());
11
12    // Set up a stream.
13    let ut_stream = space_center.get_ut_stream()?;
14    ut_stream.set_rate(1f32)?;
15
16    // Wait for updates, and print the current value.
17    for _ in 0..10 {
18        ut_stream.wait();
19        println!("It's {} o'clock", ut_stream.get()?);
20    }
21
22    Ok(())
23}
Source

pub fn wait(&self)

Block the current thread of execution until this stream receives an update from the server.

Examples found in repository?
examples/streams.rs (line 18)
7fn main() -> Result<(), Box<dyn Error>> {
8    let client = Client::new("kRPC TEST", "127.0.0.1", 50000, 50001)?;
9
10    let space_center = SpaceCenter::new(client.clone());
11
12    // Set up a stream.
13    let ut_stream = space_center.get_ut_stream()?;
14    ut_stream.set_rate(1f32)?;
15
16    // Wait for updates, and print the current value.
17    for _ in 0..10 {
18        ut_stream.wait();
19        println!("It's {} o'clock", ut_stream.get()?);
20    }
21
22    Ok(())
23}

Trait Implementations§

Source§

impl<T: RpcType + Send> Drop for Stream<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Stream<T>

§

impl<T> RefUnwindSafe for Stream<T>
where T: RefUnwindSafe,

§

impl<T> Send for Stream<T>

§

impl<T> Sync for Stream<T>
where T: Sync,

§

impl<T> Unpin for Stream<T>
where T: Unpin,

§

impl<T> UnwindSafe for Stream<T>
where T: UnwindSafe,

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> 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, 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.