Skip to content

Commit

Permalink
Fix doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Mar 2, 2024
1 parent 4ddefa0 commit 38d8ab7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 42 deletions.
6 changes: 3 additions & 3 deletions plugins/zenoh-plugin-storage-manager/src/replica/aligner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Aligner {
let properties = format!("timestamp={}&{}=cold", other.timestamp, ERA);
let (reply_content, mut no_err) = self.perform_query(other_rep, properties).await;
let mut other_intervals: HashMap<u64, u64> = HashMap::new();
// expecting sample.value to be a vec of intervals with their checksum
// expecting sample.payload to be a vec of intervals with their checksum
for each in reply_content {
match serde_json::from_str(&StringOrBase64::from(each.payload)) {
Ok((i, c)) => {
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Aligner {
INTERVALS,
diff_string.join(",")
);
// expecting sample.value to be a vec of subintervals with their checksum
// expecting sample.payload to be a vec of subintervals with their checksum
let (reply_content, mut no_err) = self.perform_query(other_rep, properties).await;
let mut other_subintervals: HashMap<u64, u64> = HashMap::new();
for each in reply_content {
Expand Down Expand Up @@ -296,7 +296,7 @@ impl Aligner {
SUBINTERVALS,
diff_string.join(",")
);
// expecting sample.value to be a vec of log entries with their checksum
// expecting sample.payload to be a vec of log entries with their checksum
let (reply_content, mut no_err) = self.perform_query(other_rep, properties).await;
let mut other_content: HashMap<u64, Vec<LogEntry>> = HashMap::new();
for each in reply_content {
Expand Down
6 changes: 3 additions & 3 deletions zenoh/src/liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// let session = zenoh::open(config::peer()).res().await.unwrap();
/// let subscriber = session
/// .declare_subscriber("key/expression")
/// .callback(|sample| { println!("Received: {} {}", sample.key_expr, sample.value); })
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.payload); })
/// .res()
/// .await
/// .unwrap();
Expand Down Expand Up @@ -500,7 +500,7 @@ impl<'a, 'b> LivelinessSubscriberBuilder<'a, 'b, DefaultHandler> {
/// .await
/// .unwrap();
/// while let Ok(sample) = subscriber.recv_async().await {
/// println!("Received: {} {}", sample.key_expr, sample.value);
/// println!("Received: {} {:?}", sample.key_expr, sample.payload);
/// }
/// # })
/// ```
Expand Down Expand Up @@ -595,7 +595,7 @@ where
/// while let Ok(token) = tokens.recv_async().await {
/// match token.sample {
/// Ok(sample) => println!("Alive token ('{}')", sample.key_expr.as_str()),
/// Err(err) => println!("Received (ERROR: '{}')", err),
/// Err(err) => println!("Received (ERROR: '{:?}')", err.payload),
/// }
/// }
/// # })
Expand Down
25 changes: 8 additions & 17 deletions zenoh/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,11 @@ impl Payload {
/// Encode an object of type `T` as a [`Value`] using the [`DefaultSerializer`].
///
/// ```rust
/// use zenoh::value::Value;
/// use zenoh::payload::Payload;
///
/// let start = String::from("abc");
/// let payload = Payload::serialize(start.clone());
/// let end: String = payload.decode().unwrap();
/// let end: String = payload.deserialize().unwrap();
/// assert_eq!(start, end);
/// ```
pub fn serialize<T>(t: T) -> Self
Expand All @@ -505,39 +505,30 @@ impl Payload {
/// Encode an object of type `T` as a [`Value`] using a provided [`Serialize`].
///
/// ```rust
/// use zenoh::prelude::sync::*;
/// use zenoh::prelude::{SplitBuffer, Payload, Serialize, Deserialize};
/// use zenoh_result::{self, zerror, ZError, ZResult};
/// use zenoh::encoding::{Serialize, Deserialize};
///
/// struct MySerialize;
///
/// impl MySerialize {
/// pub const STRING: Encoding = Encoding::new(2);
/// }
///
/// impl Serialize<String> for MySerialize {
/// type Output = Value;
/// type Output = Payload;
///
/// fn serialize(self, s: String) -> Self::Output {
/// Value::new(s.into_bytes().into()).with_encoding(MySerialize::STRING)
/// Payload::new(s.into_bytes())
/// }
/// }
///
/// impl Deserialize<String> for MySerialize {
/// type Error = ZError;
///
/// fn deserialize(self, v: &Value) -> Result<String, Self::Error> {
/// if v.encoding == MySerialize::STRING {
/// String::from_utf8(v.payload.contiguous().to_vec()).map_err(|e| zerror!("{}", e))
/// } else {
/// Err(zerror!("Invalid encoding"))
/// }
/// fn deserialize(self, v: &Payload) -> Result<String, Self::Error> {
/// String::from_utf8(v.contiguous().to_vec()).map_err(|e| zerror!("{}", e))
/// }
/// }
///
/// let start = String::from("abc");
/// let payload = Payload::serialize_with(start.clone(), MySerialize);
/// let end: String = value.decode_with(MySerialize).unwrap();
/// let end: String = payload.deserialize_with(MySerialize).unwrap();
/// assert_eq!(start, end);
/// ```
pub fn serialize_with<T, M>(t: T, m: M) -> Self
Expand Down
16 changes: 4 additions & 12 deletions zenoh/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@ pub(crate) mod common {
writer::HasWriter,
};
pub use zenoh_core::Resolve;
pub use zenoh_protocol::core::{Encoding, EncodingPrefix, EndPoint, Locator, ZenohId};

pub(crate) type Id = usize;

pub use crate::config::{self, Config, ValidatedMap};
pub use crate::handlers::IntoCallbackReceiverPair;
pub use crate::selector::{Parameter, Parameters, Selector};
pub use crate::session::{Session, SessionDeclarations};

pub use crate::query::{QueryConsolidation, QueryTarget};
pub use crate::query::{ConsolidationMode, QueryConsolidation, QueryTarget};
pub use crate::selector::{Parameter, Parameters, Selector};

/// The encoding of a zenoh `Value`.
pub use crate::payload::{DefaultSerializer, Deserialize, Payload, Serialize};
pub use crate::value::Value;
pub use zenoh_protocol::core::{Encoding, EncodingPrefix};
pub use crate::value::{DefaultEncoding, Value};

pub use crate::query::ConsolidationMode;
#[zenoh_macros::unstable]
pub use crate::sample::Locality;
#[cfg(not(feature = "unstable"))]
Expand All @@ -57,13 +56,6 @@ pub(crate) mod common {
#[zenoh_macros::unstable]
pub use crate::publication::PublisherDeclarations;
pub use zenoh_protocol::core::{CongestionControl, Reliability, WhatAmI};

/// A [`Locator`] contains a choice of protocol, an address and port, as well as optional additional properties to work with.
pub use zenoh_protocol::core::EndPoint;
/// A [`Locator`] contains a choice of protocol, an address and port, as well as optional additional properties to work with.
pub use zenoh_protocol::core::Locator;
/// The global unique id of a zenoh peer.
pub use zenoh_protocol::core::ZenohId;
}

/// Prelude to import when using Zenoh's sync API.
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ impl Session {
/// let session = zenoh::open(config::peer()).res().await.unwrap();
/// session
/// .put("key/expression", "value")
/// .encoding(DefaultEncoding::TEXT_PLAIN)
/// .with_encoding(DefaultEncoding::TEXT_PLAIN)
/// .res()
/// .await
/// .unwrap();
Expand Down
12 changes: 6 additions & 6 deletions zenoh/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl fmt::Debug for SubscriberState {
/// let session = zenoh::open(config::peer()).res().await.unwrap();
/// let subscriber = session
/// .declare_subscriber("key/expression")
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.value) })
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.payload) })
/// .res()
/// .await
/// .unwrap();
Expand Down Expand Up @@ -95,7 +95,7 @@ pub(crate) struct SubscriberInner<'a> {
/// let session = zenoh::open(config::peer()).res().await.unwrap();
/// let subscriber = session
/// .declare_subscriber("key/expression")
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.value); })
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.payload); })
/// .pull_mode()
/// .res()
/// .await
Expand All @@ -118,7 +118,7 @@ impl<'a> PullSubscriberInner<'a> {
/// let session = zenoh::open(config::peer()).res().await.unwrap();
/// let subscriber = session
/// .declare_subscriber("key/expression")
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.value); })
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.payload); })
/// .pull_mode()
/// .res()
/// .await
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<'a, 'b, Mode> SubscriberBuilder<'a, 'b, Mode, DefaultHandler> {
/// let session = zenoh::open(config::peer()).res().await.unwrap();
/// let subscriber = session
/// .declare_subscriber("key/expression")
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.value); })
/// .callback(|sample| { println!("Received: {} {:?}", sample.key_expr, sample.payload); })
/// .res()
/// .await
/// .unwrap();
Expand Down Expand Up @@ -402,7 +402,7 @@ impl<'a, 'b, Mode> SubscriberBuilder<'a, 'b, Mode, DefaultHandler> {
/// .await
/// .unwrap();
/// while let Ok(sample) = subscriber.recv_async().await {
/// println!("Received: {} {:?}", sample.key_expr, sample.value);
/// println!("Received: {} {:?}", sample.key_expr, sample.payload);
/// }
/// # })
/// ```
Expand Down Expand Up @@ -631,7 +631,7 @@ where
/// .await
/// .unwrap();
/// while let Ok(sample) = subscriber.recv_async().await {
/// println!("Received: {} {:?}", sample.key_expr, sample.value);
/// println!("Received: {} {:?}", sample.key_expr, sample.payload);
/// }
/// # })
/// ```
Expand Down

0 comments on commit 38d8ab7

Please sign in to comment.