Struct zenoh::Workspace [−][src]
pub struct Workspace<'a> { /* fields omitted */ }
Expand description
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
Returns the prefix that was used to create this Workspace (calling Zenoh::workspace()
).
Returns the zenoh-net Session
used by this workspace.
This is for advanced use cases requiring fine usage of the zenoh-net API.
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();
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();
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
)
}
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 ChangeReceiver::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 fn subscribe_with_callback<SubscribeCallback>(
&self,
selector: &Selector,
callback: SubscribeCallback
) -> impl ZFuture<Output = ZResult<SubscriberHandle<'_>>> where
SubscribeCallback: FnMut(Change) + Send + Sync + 'static,
pub fn subscribe_with_callback<SubscribeCallback>(
&self,
selector: &Selector,
callback: SubscribeCallback
) -> impl ZFuture<Output = 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 fn register_eval(
&self,
path_expr: &PathExpr
) -> impl ZFuture<Output = ZResult<GetRequestStream<'_>>>
pub fn register_eval(
&self,
path_expr: &PathExpr
) -> impl ZFuture<Output = 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_async("/demo/example/eval".try_into().unwrap(), v).await;
}
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Workspace<'a>
impl<'a> !UnwindSafe for Workspace<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more