Struct zenoh::Workspace [−][src]
A Workspace to operate on zenoh.
A Workspace has an optional Path prefix from which relative Paths or Selectors can be used.
Examples
use zenoh::*; use std::convert::TryInto; #[async_std::main] async fn main() { let zenoh = Zenoh::new(net::config::default()).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 fn prefix(&self) -> &Option<Path>
[src]
Returns the prefix that was used to create this Workspace (calling Zenoh::workspace()
).
pub fn session(&self) -> &Session
[src]
Returns the zenoh-net Session
used by this workspace.
This is for advanced use cases requiring fine usage of the zenoh-net API.
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()).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()).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]
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()).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]
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()).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,
callback: SubscribeCallback
) -> ZResult<SubscriberHandle<'_>> where
SubscribeCallback: FnMut(Change) + Send + Sync + 'static,
[src]
&self,
selector: &Selector,
callback: 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()).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()).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; }
Trait Implementations
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,
pub 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.
pub 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.
pub 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>,