[−][src]Struct zenoh::Workspace
A Workspace to operate on zenoh.
A Workspace has an optional Path prefix from which relative Paths or Selectors can be used.async_std
Examples
use zenoh::*; use std::convert::TryInto; #[async_std::main] async fn main() { let zenoh = Zenoh::new(net::Config::default(), None).await.unwrap(); // Create a Workspace using prefix "/demo/example" let workspace = zenoh.workspace(Some("/demo/example".try_into().unwrap())).await.unwrap(); // Put using a relative path: "/demo/example/" + "hello" workspace.put(&"hello".try_into().unwrap(), "Hello World!".into() ).await.unwrap(); // Note that absolute paths and selectors can still be used: workspace.put(&"/demo/exmaple/hello2".try_into().unwrap(), "Hello World!".into() ).await.unwrap(); zenoh.close().await.unwrap(); }
Implementations
impl<'_> Workspace<'_>
[src]
pub async fn put<'_, '_>(&'_ self, path: &'_ Path, value: Value) -> ZResult<()>
[src]
Put a Path
/Value
into zenoh.
The corresponding Change
will be received by all matching subscribers and all matching storages.
Note that the Path
can be absolute or relative to this Workspace.
Examples
use zenoh::*; use std::convert::TryInto; let zenoh = Zenoh::new(net::Config::default(), None).await.unwrap(); let workspace = zenoh.workspace(None).await.unwrap(); workspace.put( &"/demo/example/hello".try_into().unwrap(), "Hello World!".into() ).await.unwrap();
pub async fn delete<'_, '_>(&'_ self, path: &'_ Path) -> ZResult<()>
[src]
Delete a Path
and its Value
from zenoh.
The corresponding Change
will be received by all matching subscribers and all matching storages.
Note that the Path
can be absolute or relative to this Workspace.
Examples
use zenoh::*; use std::convert::TryInto; let zenoh = Zenoh::new(net::Config::default(), None).await.unwrap(); let workspace = zenoh.workspace(None).await.unwrap(); workspace.delete( &"/demo/example/hello".try_into().unwrap() ).await.unwrap();
pub async fn get<'_, '_>(
&'_ self,
selector: &'_ Selector
) -> ZResult<DataStream>
[src]
&'_ self,
selector: &'_ Selector
) -> ZResult<DataStream>
Get a selection of Path
/Value
from zenoh.
The selection is returned as a async_std::stream::Stream
of Data
.
Note that the Selector
can be absolute or relative to this Workspace.
Examples
use zenoh::*; use std::convert::TryInto; use futures::prelude::*; let zenoh = Zenoh::new(net::Config::default(), None).await.unwrap(); let workspace = zenoh.workspace(None).await.unwrap(); let mut data_stream = workspace.get(&"/demo/example/**".try_into().unwrap()).await.unwrap(); while let Some(data) = data_stream.next().await { println!(">> {} : {:?} at {}", data.path, data.value, data.timestamp ) }
pub async fn subscribe<'_, '_, '_>(
&'_ self,
selector: &'_ Selector
) -> ZResult<ChangeStream<'_>>
[src]
&'_ self,
selector: &'_ Selector
) -> ZResult<ChangeStream<'_>>
Subscribe to changes for a selection of Path
/Value
(specified via a Selector
) from zenoh.
The changes are returned as async_std::stream::Stream
of Change
.
This Stream will never end unless it's dropped or explicitly closed via ChangeStream::close()
.
Note that the Selector
can be absolute or relative to this Workspace.
Examples
use zenoh::*; use std::convert::TryInto; use futures::prelude::*; let zenoh = Zenoh::new(net::Config::default(), None).await.unwrap(); let workspace = zenoh.workspace(None).await.unwrap(); let mut change_stream = workspace.subscribe(&"/demo/example/**".try_into().unwrap()).await.unwrap(); while let Some(change) = change_stream.next().await { println!(">> {:?} for {} : {:?} at {}", change.kind, change.path, change.value, change.timestamp ) }
pub async fn subscribe_with_callback<SubscribeCallback, '_, '_, '_>(
&'_ self,
selector: &'_ Selector,
__arg2: SubscribeCallback
) -> ZResult<SubscriberHandle<'_>> where
SubscribeCallback: FnMut(Change) + Send + Sync + 'static,
[src]
&'_ self,
selector: &'_ Selector,
__arg2: SubscribeCallback
) -> ZResult<SubscriberHandle<'_>> where
SubscribeCallback: FnMut(Change) + Send + Sync + 'static,
Subscribe to changes for a selection of Path
/Value
(specified via a Selector
) from zenoh.
For each change, the callback
will be called.
A SubscriberHandle
is returned, allowing to close the subscription via SubscriberHandle::close()
.
Note that the Selector
can be absolute or relative to this Workspace.
Examples
use zenoh::*; use std::convert::TryInto; let zenoh = Zenoh::new(net::Config::default(), None).await.unwrap(); let workspace = zenoh.workspace(None).await.unwrap(); let mut change_stream = workspace.subscribe_with_callback( &"/demo/example/**".try_into().unwrap(), move |change| { println!(">> {:?} for {} : {:?} at {}", change.kind, change.path, change.value, change.timestamp )} ).await.unwrap();
pub async fn register_eval<'_, '_, '_>(
&'_ self,
path_expr: &'_ PathExpr
) -> ZResult<GetRequestStream<'_>>
[src]
&'_ self,
path_expr: &'_ PathExpr
) -> ZResult<GetRequestStream<'_>>
Registers an evaluation function under the provided PathExpr
.
A async_std::stream::Stream
of GetRequest
is returned.
All get
requests matching the PathExpr
will be added to this stream as a GetRequest
,
allowing the implementation to send a reply as a result of the evaluation function via GetRequest::reply()
.
This Stream will never end unless it's dropped or explicitly closed via GetRequestStream::close()
.
Note that the PathExpr
can be absolute or relative to this Workspace.
Examples
use zenoh::*; use std::convert::TryInto; use futures::prelude::*; let zenoh = Zenoh::new(net::Config::default(), None).await.unwrap(); let workspace = zenoh.workspace(None).await.unwrap(); let mut get_stream = workspace.register_eval(&"/demo/example/eval".try_into().unwrap()).await.unwrap(); while let Some(get_request) = get_stream.next().await { println!( ">> [Eval function] received get with selector: {}", get_request.selector ); // return the Value as a result of this evaluation function : let v = Value::StringUTF8(format!("Result for get on {}", get_request.selector)); get_request.reply("/demo/example/eval".try_into().unwrap(), v).await; }
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Workspace<'a>
impl<'a> Send for Workspace<'a>
impl<'a> Sync for Workspace<'a>
impl<'a> Unpin for Workspace<'a>
impl<'a> !UnwindSafe for Workspace<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,