Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample api rework update #907

Merged
merged 3 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions zenoh/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ pub(crate) mod common {
pub use crate::publication::PublisherDeclarations;
pub use zenoh_protocol::core::{CongestionControl, Reliability, WhatAmI};

pub use crate::sample::builder::{
QoSBuilderTrait, SampleBuilderTrait, TimestampBuilderTrait, ValueBuilderTrait,
};
pub use crate::sample::builder::{QoSBuilderTrait, TimestampBuilderTrait, ValueBuilderTrait};

#[zenoh_macros::unstable]
pub use crate::sample::builder::SampleBuilderTrait;
}

/// Prelude to import when using Zenoh's sync API.
Expand Down
15 changes: 13 additions & 2 deletions zenoh/src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ use crate::encoding::Encoding;
use crate::handlers::{locked, DefaultHandler};
use crate::net::primitives::Primitives;
use crate::prelude::*;
use crate::sample::builder::SampleBuilder;
use crate::sample::{QoSBuilder, SourceInfo};
use crate::Id;
use crate::SessionRef;
use crate::Undeclarable;
#[cfg(feature = "unstable")]
use crate::{query::ReplyKeyExpr, sample::Attachment};
use crate::{query::ReplyKeyExpr, sample::builder::SampleBuilder, sample::Attachment};
use std::fmt;
use std::future::Ready;
use std::ops::Deref;
Expand Down Expand Up @@ -98,6 +97,18 @@ impl Query {
self.inner.value.as_ref()
}

/// This Query's payload.
#[inline(always)]
pub fn payload(&self) -> Option<&Payload> {
self.inner.value.as_ref().map(|v| &v.payload)
}

/// This Query's encoding.
#[inline(always)]
pub fn encoding(&self) -> Option<&Encoding> {
self.inner.value.as_ref().map(|v| &v.encoding)
}

#[zenoh_macros::unstable]
pub fn attachment(&self) -> Option<&Attachment> {
self.inner.attachment.as_ref()
Expand Down
8 changes: 3 additions & 5 deletions zenoh/src/sample/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
use std::marker::PhantomData;

#[cfg(feature = "unstable")]
use crate::sample::Attachment;
use crate::sample::QoS;
use crate::sample::QoSBuilder;
#[cfg(feature = "unstable")]
use crate::sample::SourceInfo;
use crate::sample::{Attachment, SourceInfo};
use crate::sample::{QoS, QoSBuilder};
use crate::Encoding;
use crate::KeyExpr;
use crate::Payload;
Expand Down Expand Up @@ -47,6 +44,7 @@ pub trait TimestampBuilderTrait {
fn timestamp<T: Into<Option<Timestamp>>>(self, timestamp: T) -> Self;
}

#[zenoh_macros::unstable]
pub trait SampleBuilderTrait {
/// Attach source information
#[zenoh_macros::unstable]
Expand Down
1 change: 1 addition & 0 deletions zenoh/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::Priority;
use crate::Sample;
use crate::SampleKind;
use crate::Selector;
#[cfg(feature = "unstable")]
use crate::SourceInfo;
use crate::Value;
use log::{error, trace, warn};
Expand Down
1 change: 0 additions & 1 deletion zenoh/tests/qos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//
use std::time::Duration;
use zenoh::prelude::r#async::*;
use zenoh::sample::builder::QoSBuilderTrait;
use zenoh::{publication::Priority, SessionDeclarations};
use zenoh_core::ztimeout;

Expand Down
1 change: 0 additions & 1 deletion zenoh/tests/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::time::Duration;
use tokio_util::{sync::CancellationToken, task::TaskTracker};
use zenoh::config::{Config, ModeDependentValue};
use zenoh::prelude::r#async::*;
use zenoh::sample::builder::QoSBuilderTrait;
use zenoh::Result;
use zenoh_core::ztimeout;
use zenoh_protocol::core::{WhatAmI, WhatAmIMatcher};
Expand Down
Loading