Skip to content

Commit

Permalink
placing unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Mar 31, 2024
1 parent 7afbc0d commit 21670cd
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 36 deletions.
38 changes: 20 additions & 18 deletions commons/zenoh-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn keformat_support(source: &str) -> proc_macro2::TokenStream {
let id = &source[spec.spec_start..(spec.spec_start + spec.id_end as usize)];
let set_id = quote::format_ident!("{}", id);
quote! {
pub fn #set_id <S: ::core::fmt::Display>(&mut self, value: S) -> Result<&mut Self, ::zenoh::key_expr::format::FormatSetError> {
pub fn #set_id <S: ::core::fmt::Display>(&mut self, value: S) -> Result<&mut Self, ::zenoh_keyexpr::key_expr::format::FormatSetError> {
match self.0.set(#id, value) {
Ok(_) => Ok(self),
Err(e) => Err(e)
Expand All @@ -109,18 +109,18 @@ fn keformat_support(source: &str) -> proc_macro2::TokenStream {
quote! {
#[doc = #doc]
/// Since the pattern is `**`, this may return `None` if the pattern didn't consume any chunks.
pub fn #get_id (&self) -> Option<& ::zenoh::key_expr::keyexpr> {
pub fn #get_id (&self) -> Option<& ::zenoh_keyexpr::key_expr::keyexpr> {
unsafe {
let s =self._0.get(#id).unwrap_unchecked();
(!s.is_empty()).then(|| ::zenoh::key_expr::keyexpr::from_str_unchecked(s))
(!s.is_empty()).then(|| ::zenoh_keyexpr::key_expr::keyexpr::from_str_unchecked(s))
}
}
}
} else {
quote! {
#[doc = #doc]
pub fn #get_id (&self) -> &::zenoh::key_expr::keyexpr {
unsafe {::zenoh::key_expr::keyexpr::from_str_unchecked(self._0.get(#id).unwrap_unchecked())}
pub fn #get_id (&self) -> &::zenoh_keyexpr::key_expr::keyexpr {
unsafe {::zenoh_keyexpr::key_expr::keyexpr::from_str_unchecked(self._0.get(#id).unwrap_unchecked())}
}
}
}
Expand All @@ -136,7 +136,7 @@ fn keformat_support(source: &str) -> proc_macro2::TokenStream {
segment_end,
} = spec;
quote! {
::zenoh::key_expr::format::macro_support::SegmentBuilder {
::zenoh_keyexpr::key_expr::format::macro_support::SegmentBuilder {
segment_start: #segment_start,
prefix_end: #prefix_end,
spec_start: #spec_start,
Expand All @@ -152,17 +152,17 @@ fn keformat_support(source: &str) -> proc_macro2::TokenStream {
let formatter_doc = format!("And instance of a formatter for `{source}`.");

quote! {
use ::zenoh::Result as ZResult;
const FORMAT_INNER: ::zenoh::key_expr::format::KeFormat<'static, [::zenoh::key_expr::format::Segment<'static>; #len]> = unsafe {
::zenoh::key_expr::format::macro_support::const_new(#source, [#(#segments)*])
use ::zenoh_core::Result as ZResult;
const FORMAT_INNER: ::zenoh_keyexpr::key_expr::format::KeFormat<'static, [::zenoh_keyexpr::key_expr::format::Segment<'static>; #len]> = unsafe {
::zenoh_keyexpr::key_expr::format::macro_support::const_new(#source, [#(#segments)*])
};
#[doc = #format_doc]
#[derive(Copy, Clone, Hash)]
pub struct Format;

#[doc = #formatter_doc]
#[derive(Clone)]
pub struct Formatter(::zenoh::key_expr::format::KeFormatter<'static, [::zenoh::key_expr::format::Segment<'static>; #len]>);
pub struct Formatter(::zenoh_keyexpr::key_expr::format::KeFormatter<'static, [::zenoh_keyexpr::key_expr::format::Segment<'static>; #len]>);
impl ::core::fmt::Debug for Format {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Debug::fmt(&FORMAT_INNER, f)
Expand All @@ -179,11 +179,11 @@ fn keformat_support(source: &str) -> proc_macro2::TokenStream {
}
}
impl ::core::ops::Deref for Format {
type Target = ::zenoh::key_expr::format::KeFormat<'static, [::zenoh::key_expr::format::Segment<'static>; #len]>;
type Target = ::zenoh_keyexpr::key_expr::format::KeFormat<'static, [::zenoh_keyexpr::key_expr::format::Segment<'static>; #len]>;
fn deref(&self) -> &Self::Target {&FORMAT_INNER}
}
impl ::core::ops::Deref for Formatter {
type Target = ::zenoh::key_expr::format::KeFormatter<'static, [::zenoh::key_expr::format::Segment<'static>; #len]>;
type Target = ::zenoh_keyexpr::key_expr::format::KeFormatter<'static, [::zenoh_keyexpr::key_expr::format::Segment<'static>; #len]>;
fn deref(&self) -> &Self::Target {&self.0}
}
impl ::core::ops::DerefMut for Formatter {
Expand All @@ -192,9 +192,9 @@ fn keformat_support(source: &str) -> proc_macro2::TokenStream {
impl Formatter {
#(#setters)*
}
pub struct Parsed<'s>{_0: ::zenoh::key_expr::format::Parsed<'s, [::zenoh::key_expr::format::Segment<'s>; #len]>}
pub struct Parsed<'s>{_0: ::zenoh_keyexpr::key_expr::format::Parsed<'s, [::zenoh_keyexpr::key_expr::format::Segment<'s>; #len]>}
impl<'s> ::core::ops::Deref for Parsed<'s> {
type Target = ::zenoh::key_expr::format::Parsed<'s, [::zenoh::key_expr::format::Segment<'s>; #len]>;
type Target = ::zenoh_keyexpr::key_expr::format::Parsed<'s, [::zenoh_keyexpr::key_expr::format::Segment<'s>; #len]>;
fn deref(&self) -> &Self::Target {&self._0}
}
impl Parsed<'_> {
Expand All @@ -204,17 +204,17 @@ fn keformat_support(source: &str) -> proc_macro2::TokenStream {
pub fn formatter() -> Formatter {
Formatter(Format.formatter())
}
pub fn parse<'s>(target: &'s ::zenoh::key_expr::keyexpr) -> ZResult<Parsed<'s>> {
pub fn parse<'s>(target: &'s ::zenoh_keyexpr::key_expr::keyexpr) -> ZResult<Parsed<'s>> {
Ok(Parsed{_0: Format.parse(target)?})
}
pub fn into_inner(self) -> ::zenoh::key_expr::format::KeFormat<'static, [::zenoh::key_expr::format::Segment<'static>; #len]> {
pub fn into_inner(self) -> ::zenoh_keyexpr::key_expr::format::KeFormat<'static, [::zenoh_keyexpr::key_expr::format::Segment<'static>; #len]> {
FORMAT_INNER
}
}
pub fn formatter() -> Formatter {
Format::formatter()
}
pub fn parse<'s>(target: &'s ::zenoh::key_expr::keyexpr) -> ZResult<Parsed<'s>> {
pub fn parse<'s>(target: &'s ::zenoh_keyexpr::key_expr::keyexpr) -> ZResult<Parsed<'s>> {
Format::parse(target)
}
}
Expand Down Expand Up @@ -348,7 +348,9 @@ pub fn ke(tokens: TokenStream) -> TokenStream {
let value: LitStr = syn::parse(tokens).unwrap();
let ke = value.value();
match zenoh_keyexpr::keyexpr::new(&ke) {
Ok(_) => quote!(unsafe {::zenoh::key_expr::keyexpr::from_str_unchecked(#ke)}).into(),
Ok(_) => {
quote!(unsafe {::zenoh_keyexpr::key_expr::keyexpr::from_str_unchecked(#ke)}).into()
}
Err(e) => panic!("{}", e),
}
}
2 changes: 1 addition & 1 deletion zenoh/src/api/key_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use std::{
str::FromStr,
};
use zenoh_core::{AsyncResolve, Resolvable, SyncResolve};
use zenoh_keyexpr::{keyexpr, OwnedKeyExpr};
use zenoh_keyexpr::{keyexpr, OwnedKemtExpr};
use zenoh_protocol::{
core::{key_expr::canon::Canonizable, ExprId, WireExpr},
network::{declare, DeclareBody, Mapping, UndeclareKeyExpr},
Expand Down
7 changes: 5 additions & 2 deletions zenoh/src/api/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
//

//! Publishing primitives.
#[zenoh_macros::unstable]
use crate::api::sample::attachment::Attachment;
#[zenoh_macros::unstable]
use crate::api::sample::SourceInfo;
use crate::api::{
encoding::Encoding,
handlers::{locked, Callback, DefaultHandler, IntoHandler},
key_expr::{KeyExpr, KeyExprInner},
payload::Payload,
sample::{
attachment::Attachment,
builder::{QoSBuilderTrait, SampleBuilderTrait, TimestampBuilderTrait, ValueBuilderTrait},
DataInfo, Locality, QoS, Sample, SampleFields, SampleKind, SourceInfo,
DataInfo, Locality, QoS, Sample, SampleFields, SampleKind,
},
session::{SessionRef, Undeclarable},
value::Value,
Expand Down
4 changes: 3 additions & 1 deletion zenoh/src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
//

//! Query primitives.
#[zenoh_macros::unstable]
use crate::api::sample::SourceInfo;
use crate::api::{
encoding::Encoding,
handlers::{locked, Callback, DefaultHandler, IntoHandler},
Expand All @@ -22,7 +24,7 @@ use crate::api::{
sample::{
attachment::Attachment,
builder::{QoSBuilderTrait, SampleBuilderTrait, ValueBuilderTrait},
Locality, QoSBuilder, Sample, SourceInfo,
Locality, QoSBuilder, Sample,
},
selector::Selector,
session::Session,
Expand Down
7 changes: 5 additions & 2 deletions zenoh/src/api/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@
//

//! Queryable primitives.
#[zenoh_macros::unstable]
use crate::api::query::ReplyKeyExpr;
#[zenoh_macros::unstable]
use crate::api::sample::SourceInfo;
use crate::api::{
encoding::Encoding,
handlers::{locked, DefaultHandler, IntoHandler},
key_expr::KeyExpr,
payload::Payload,
publication::Priority,
query::ReplyKeyExpr,
sample::{
attachment::Attachment,
builder::{
DeleteSampleBuilder, PutSampleBuilder, QoSBuilderTrait, SampleBuilder,
SampleBuilderTrait, TimestampBuilderTrait, ValueBuilderTrait,
},
Locality, Sample, SampleKind, SourceInfo,
Locality, Sample, SampleKind,
},
selector::{Parameters, Selector},
session::{SessionRef, Undeclarable},
Expand Down
8 changes: 7 additions & 1 deletion zenoh/src/api/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ impl DataInfoIntoSample for Option<DataInfo> {
IntoPayload: Into<Payload>,
{
if let Some(data_info) = self {
data_info.into_sample(key_expr, payload, attachment)
data_info.into_sample(
key_expr,
payload,
#[cfg(feature = "unstable")]
attachment,
)
} else {
Sample {
key_expr: key_expr.into(),
Expand Down Expand Up @@ -175,6 +180,7 @@ impl SourceInfo {
}
}

#[cfg(feature = "unstable")]
impl From<SourceInfo> for Option<zenoh::put::ext::SourceInfoType> {
fn from(source_info: SourceInfo) -> Option<zenoh::put::ext::SourceInfoType> {
if source_info.is_empty() {
Expand Down
6 changes: 5 additions & 1 deletion zenoh/src/api/sample/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
#[zenoh_macros::unstable]
use crate::api::sample::Attachment;
#[zenoh_macros::unstable]
use crate::api::sample::SourceInfo;
use crate::api::{
encoding::Encoding,
key_expr::KeyExpr,
payload::Payload,
publication::Priority,
sample::{Attachment, QoS, QoSBuilder, Sample, SourceInfo},
sample::{QoS, QoSBuilder, Sample},
value::Value,
};
use uhlc::Timestamp;
Expand Down
14 changes: 9 additions & 5 deletions zenoh/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
#[zenoh_macros::unstable]
use crate::api::liveliness::{Liveliness, LivelinessTokenState, PREFIX_LIVELINESS};
#[zenoh_macros::unstable]
use crate::api::sample::attachment::Attachment;
#[zenoh_macros::unstable]
use crate::api::sample::SourceInfo;
use crate::api::{
admin,
encoding::Encoding,
handlers::{Callback, DefaultHandler},
info::*,
key_expr::{KeyExpr, KeyExprInner},
liveliness::{Liveliness, LivelinessTokenState, PREFIX_LIVELINESS},
payload::Payload,
publication::*,
query::*,
queryable::*,
sample::{
attachment::Attachment, DataInfo, DataInfoIntoSample, Locality, QoS, Sample, SampleKind,
SourceInfo,
},
sample::{DataInfo, DataInfoIntoSample, Locality, QoS, Sample, SampleKind},
selector::{Parameters, Selector, TIME_RANGE_KEY},
subscriber::*,
value::Value,
Expand Down Expand Up @@ -797,6 +799,7 @@ impl Session {
#[cfg(feature = "unstable")]
attachment: None,
handler: DefaultHandler,
#[cfg(feature = "unstable")]
source_info: SourceInfo::empty(),
}
}
Expand Down Expand Up @@ -1663,6 +1666,7 @@ impl Session {
payload: RequestBody::Query(zenoh_protocol::zenoh::Query {
consolidation,
parameters: selector.parameters().to_string(),
#[cfg(feature = "unstable")]
ext_sinfo: source.into(),
ext_body: value.as_ref().map(|v| query::ext::QueryBodyType {
#[cfg(feature = "shared-memory")]
Expand Down
3 changes: 2 additions & 1 deletion zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ pub mod session {

pub mod key_expr {
pub use crate::api::key_expr::KeyExpr;
pub use zenoh_keyexpr::key_expr;
pub use zenoh_keyexpr::key_expr::format::KeFormat;
pub use zenoh_keyexpr::keyexpr;
pub use zenoh_keyexpr::OwnedKeyExpr;
pub use zenoh_macros::{kedefine, keformat};
}
Expand Down
8 changes: 6 additions & 2 deletions zenoh/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ pub(crate) mod common {

#[zenoh_macros::unstable]
pub use crate::sample::Attachment;
#[zenoh_macros::unstable]
pub use crate::sample::Locality;
#[zenoh_macros::unstable]
pub use crate::sample::SourceInfo;
pub use crate::sample::{
Locality, QoSBuilderTrait, Sample, SampleBuilderTrait, SampleKind, SourceInfo,
TimestampBuilderTrait, ValueBuilderTrait,
QoSBuilderTrait, Sample, SampleBuilderTrait, SampleKind, TimestampBuilderTrait,
ValueBuilderTrait,
};

pub use crate::query::Reply;
Expand Down
7 changes: 5 additions & 2 deletions zenoh/tests/unicity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::runtime::Handle;
use zenoh::config;
use zenoh::config::EndPoint;
use zenoh::config::WhatAmI;
use zenoh::core::ztimeout;
use zenoh::core::AsyncResolve;
use zenoh::sample::QoSBuilderTrait;
use zenoh::session::{open, Session};
use zenoh::key_expr::KeyExpr;
use zenoh::sample::{CongestionControl, QoSBuilderTrait};
use zenoh::session::{open, Session, SessionDeclarations};

const TIMEOUT: Duration = Duration::from_secs(60);
const SLEEP: Duration = Duration::from_secs(1);
Expand Down

0 comments on commit 21670cd

Please sign in to comment.