pub struct Query { /* private fields */ }Expand description
The request received by a Queryable.
The Query provides all data sent by Querier::get
or Session::get: the key expression, the
parameters, the payload, and the attachment, if any.
The reply to the query should be made with one of its methods:
Query::replyto reply with a dataSampleof kindPut,Query::reply_delto reply with a dataSampleof kindDelete,Query::reply_errto send an error reply.
The important detail: the Query::key_expr is not the key expression
which should be used as the parameter of reply, because it may contain globs.
The Queryable’s key expression is the one that should be used.
For example, the Query may contain the key expression foo/* and the reply
should be sent with foo/bar or foo/baz, depending on the concrete querier.
Implementations§
Source§impl Query
impl Query
Sourcepub fn key_expr(&self) -> &KeyExpr<'static>
pub fn key_expr(&self) -> &KeyExpr<'static>
The key selector part of this Query.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |query| { println!("{}", query.key_expr()); })
.await
.unwrap();Sourcepub fn parameters(&self) -> &Parameters<'static>
pub fn parameters(&self) -> &Parameters<'static>
This Query’s selector parameters.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |query| { println!("{}", query.parameters()); })
.await
.unwrap();Sourcepub fn payload(&self) -> Option<&ZBytes>
pub fn payload(&self) -> Option<&ZBytes>
This Query’s payload.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |query| {
let payload: Option<&ZBytes> = query.payload();
})
.await
.unwrap();Sourcepub fn payload_mut(&mut self) -> Option<&mut ZBytes>
pub fn payload_mut(&mut self) -> Option<&mut ZBytes>
This Query’s payload (mutable).
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |mut query| {
let payload: Option<&mut ZBytes> = query.payload_mut();
})
.await
.unwrap();Sourcepub fn encoding(&self) -> Option<&Encoding>
pub fn encoding(&self) -> Option<&Encoding>
This Query’s encoding.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |query| { println!("{:?}", query.encoding()); })
.await
.unwrap();Sourcepub fn attachment(&self) -> Option<&ZBytes>
pub fn attachment(&self) -> Option<&ZBytes>
This Query’s attachment.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |query| {
let attachment: Option<&ZBytes> = query.attachment();
})
.await
.unwrap();Sourcepub fn attachment_mut(&mut self) -> Option<&mut ZBytes>
pub fn attachment_mut(&mut self) -> Option<&mut ZBytes>
This Query’s attachment (mutable).
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |mut query| {
let attachment: Option<&mut ZBytes> = query.attachment_mut();
})
.await
.unwrap();Sourcepub fn source_info(&self) -> Option<&SourceInfo>
Available on crate feature unstable only.
pub fn source_info(&self) -> Option<&SourceInfo>
unstable only.Gets info on the source of this Query.
Sourcepub fn reply<'b, TryIntoKeyExpr, IntoZBytes>(
&self,
key_expr: TryIntoKeyExpr,
payload: IntoZBytes,
) -> ReplyBuilder<'_, 'b, ReplyBuilderPut>
pub fn reply<'b, TryIntoKeyExpr, IntoZBytes>( &self, key_expr: TryIntoKeyExpr, payload: IntoZBytes, ) -> ReplyBuilder<'_, 'b, ReplyBuilderPut>
Sends a Sample of kind Put
as a reply to this Query.
By default, queries only accept replies whose key expression intersects with the query’s.
Unless the query has enabled disjoint replies (you can check this through Query::accepts_replies),
replying on a disjoint key expression will result in an error when resolving the reply.
Sourcepub fn reply_err<IntoZBytes>(&self, payload: IntoZBytes) -> ReplyErrBuilder<'_>
pub fn reply_err<IntoZBytes>(&self, payload: IntoZBytes) -> ReplyErrBuilder<'_>
Sends a ReplyError as a reply to this Query.
Sourcepub fn reply_del<'b, TryIntoKeyExpr>(
&self,
key_expr: TryIntoKeyExpr,
) -> ReplyBuilder<'_, 'b, ReplyBuilderDelete>
pub fn reply_del<'b, TryIntoKeyExpr>( &self, key_expr: TryIntoKeyExpr, ) -> ReplyBuilder<'_, 'b, ReplyBuilderDelete>
Sends a Sample of kind Delete
as a reply to this Query.
By default, queries only accept replies whose key expression intersects with the query’s.
Unless the query has enabled disjoint replies (you can check this through Query::accepts_replies),
replying on a disjoint key expression will result in an error when resolving the reply.
Sourcepub fn accepts_replies(&self) -> ZResult<ReplyKeyExpr>
Available on crate feature unstable only.
pub fn accepts_replies(&self) -> ZResult<ReplyKeyExpr>
unstable only.See details in ReplyKeyExpr documentation.
§Examples
let session = zenoh::open(zenoh::Config::default()).await.unwrap();
let queryable = session
.declare_queryable("key/expression")
.callback(move |query| { query.accepts_replies(); })
.await
.unwrap();Trait Implementations§
Auto Trait Implementations§
impl Freeze for Query
impl !RefUnwindSafe for Query
impl Send for Query
impl Sync for Query
impl Unpin for Query
impl !UnwindSafe for Query
Blanket Implementations§
Source§impl<Source> AccessAs for Source
impl<Source> AccessAs for Source
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more