From 4494b8d49939db61b9e67cbb21990b122bc301fb Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 4 Sep 2024 12:42:57 +0200 Subject: [PATCH 01/17] ZBytes::iter_raw. Improve ZBytes documentation --- examples/examples/z_bytes.rs | 19 +++++++- zenoh/src/api/bytes.rs | 89 +++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/examples/examples/z_bytes.rs b/examples/examples/z_bytes.rs index ac4a2cc94a..94fc4c0915 100644 --- a/examples/examples/z_bytes.rs +++ b/examples/examples/z_bytes.rs @@ -33,7 +33,8 @@ fn main() { // Corresponding encoding to be used in operations like `.put()`, `.reply()`, etc. // let encoding = Encoding::ZENOH_STRING; - // Cow + // Cow + // See [`zenoh::bytes::ZBytes`] documentation for zero-copy behaviour. let input = Cow::from("test"); let payload = ZBytes::from(&input); let output: Cow = payload.deserialize().unwrap(); @@ -49,6 +50,15 @@ fn main() { // Corresponding encoding to be used in operations like `.put()`, `.reply()`, etc. // let encoding = Encoding::ZENOH_BYTES; + // Cow<[u8]> + // See [`zenoh::bytes::ZBytes`] documentation for zero-copy behaviour. + let input = Cow::from(vec![1, 2, 3, 4]); + let payload = ZBytes::from(&input); + let output: Cow<[u8]> = payload.into(); + assert_eq!(input, output); + // Corresponding encoding to be used in operations like `.put()`, `.reply()`, etc. + // let encoding = Encoding::ZENOH_BYTES; + // Writer & Reader // serialization let mut bytes = ZBytes::empty(); @@ -81,6 +91,13 @@ fn main() { assert_eq!(input[idx], value.unwrap()); } + // Iterator RAW + let input: [i32; 4] = [1, 2, 3, 4]; + let payload = ZBytes::from_iter(input.iter()); + for slice in payload.iter_raw() { + println!("{:02x?}", slice); + } + // HashMap let mut input: HashMap = HashMap::new(); input.insert(0, String::from("abc")); diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index 7e3083b57f..6714adc8f0 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -106,7 +106,7 @@ pub trait Deserialize { /// /// `ZBytes` provides convenient methods to the user for serialization/deserialization based on the default Zenoh serializer [`ZSerde`]. /// -/// **NOTE:** Zenoh semantic and protocol take care of sending and receiving bytes without restricting the actual data types. +/// **NOTE 1:** Zenoh semantic and protocol take care of sending and receiving bytes without restricting the actual data types. /// [`ZSerde`] is the default serializer/deserializer provided for convenience to the users to deal with primitives data types via /// a simple out-of-the-box encoding. [`ZSerde`] is **NOT** by any means the only serializer/deserializer users can use nor a limitation /// to the types supported by Zenoh. Users are free and encouraged to use any serializer/deserializer of their choice like *serde*, @@ -185,6 +185,40 @@ pub trait Deserialize { /// assert_eq!(start, end); /// ``` /// +/// **NOTE 2:** `ZBytes` may store data in non-contiguous regions of memory. +/// The typical case for `ZBytes` to store data in different memory regions is when data is received fragmented from the network. +/// The user then can decided to use [`ZBytes::deserialize`], [`ZBytes::reader`], [`ZBytes::into`], or [`ZBytes::iter_raw`] depending +/// on their needs. +/// +/// To directly access raw data as contiguous slice it is preferred to convert `ZBytes` into a [`std::borrow::Cow<[u8]>`]. +/// If `ZBytes` contains all the data in a single memory location, this is guaranteed to be zero-copy. This is the common case for small messages. +/// If `ZBytes` contains data scattered in differnt memory regions, this operation will do an allocation and a copy. This is the common case for large messages. +/// +/// Example: +/// ```rust +/// use std::borrow::Cow; +/// use zenoh::bytes::ZBytes; +/// +/// let buf: Vec = vec![0, 1, 2, 3]; +/// let bytes = ZBytes::from(buf.clone()); +/// let deser: Cow<[u8]> = bytes.into(); +/// assert_eq!(buf.as_slice(), deser.as_ref()); +/// ``` +/// +/// It is also possible to iterate over the raw data that may be scattered on different memory regions. +/// Please note that no guarantee is provided on the internal memory layout of [`ZBytes`] nor on how many slices a given [`ZBytes`] will be composed of. +/// The only provided guarantee is on the bytes order that is preserved. +/// +/// Example: +/// ```rust +/// use zenoh::bytes::ZBytes; +/// +/// let buf: Vec = vec![0, 1, 2, 3]; +/// let bytes = ZBytes::from(buf.clone()); +/// for slice in bytes.iter_raw() { +/// println!("{:02x?}", slice); +/// } +/// ``` #[repr(transparent)] #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct ZBytes(ZBuf); @@ -233,7 +267,19 @@ impl ZBytes { ZBytesWriter(self.0.writer()) } - /// Get a [`ZBytesReader`] implementing [`std::io::Read`] trait. + /// Get a [`ZBytesIterator`] that deserializes a sequence of `T`. + /// + /// Example: + /// ```rust + /// use zenoh::bytes::ZBytes; + /// + /// let list: Vec = vec![1.1, 2.2, 3.3]; + /// let mut zbs = ZBytes::from_iter(list.iter()); + /// + /// for (index, elem) in zbs.iter::().enumerate() { + /// assert_eq!(list[index], elem.unwrap()); + /// } + /// ``` pub fn iter(&self) -> ZBytesIterator<'_, T> where for<'b> ZSerde: Deserialize = &'b ZBytes>, @@ -245,6 +291,43 @@ impl ZBytes { } } + /// Return an iterator on raw bytes slices contained in the [`ZBytes`]. + /// + /// [`ZBytes`] may store data in non-contiguous regions of memory, this iterator + /// then allows to access raw data directly without any attempt of deserializing it. + /// Please note that no guarantee is provided on the internal memory layout of [`ZBytes`]. + /// The only provided guarantee is on the bytes order that is preserved. + /// + /// Please note that [`ZBytes::iter`] will perform deserialization while iterating while [`ZBytes::iter_raw`] will not. + /// + /// ```rust + /// use std::io::Write; + /// use zenoh::bytes::ZBytes; + /// + /// let buf1: Vec = vec![1, 2, 3]; + /// let buf2: Vec = vec![4, 5, 6, 7, 8]; + /// let mut zbs = ZBytes::empty(); + /// let mut writer = zbs.writer(); + /// writer.write(&buf1); + /// writer.write(&buf2); + /// + /// // Print the raw content + /// for slice in zbs.iter_raw() { + /// println!("{:02x?}", slice); + /// } + /// + /// // Concatenate input in a single vector + /// let buf: Vec = buf1.into_iter().chain(buf2.into_iter()).collect(); + /// // Concatenate raw bytes in a single vector + /// let out: Vec = zbs.iter_raw().fold(Vec::new(), |mut b, x| { b.extend_from_slice(x); b }); + /// // The previous line is the equivalent of + /// // let out: Vec = zbs.into(); + /// assert_eq!(buf, out); + /// ``` + pub fn iter_raw(&self) -> impl Iterator { + self.0.slices() + } + /// Serialize an object of type `T` as a [`ZBytes`] using the [`ZSerde`]. /// /// ```rust @@ -294,6 +377,8 @@ impl ZBytes { } /// Deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// + /// The most efficient to retrieve a contiguous view o pub fn deserialize<'a, T>(&'a self) -> Result>::Error> where ZSerde: Deserialize = &'a ZBytes>, From 070e425c807845f8ef58fa0f51879b078023aa5c Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 4 Sep 2024 12:48:46 +0200 Subject: [PATCH 02/17] Rename iter_raw to slices --- examples/examples/z_bytes.rs | 2 +- zenoh/src/api/bytes.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/examples/z_bytes.rs b/examples/examples/z_bytes.rs index 94fc4c0915..b3c994585e 100644 --- a/examples/examples/z_bytes.rs +++ b/examples/examples/z_bytes.rs @@ -94,7 +94,7 @@ fn main() { // Iterator RAW let input: [i32; 4] = [1, 2, 3, 4]; let payload = ZBytes::from_iter(input.iter()); - for slice in payload.iter_raw() { + for slice in payload.slices() { println!("{:02x?}", slice); } diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index 6714adc8f0..7df78728ab 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -187,7 +187,7 @@ pub trait Deserialize { /// /// **NOTE 2:** `ZBytes` may store data in non-contiguous regions of memory. /// The typical case for `ZBytes` to store data in different memory regions is when data is received fragmented from the network. -/// The user then can decided to use [`ZBytes::deserialize`], [`ZBytes::reader`], [`ZBytes::into`], or [`ZBytes::iter_raw`] depending +/// The user then can decided to use [`ZBytes::deserialize`], [`ZBytes::reader`], [`ZBytes::into`], or [`ZBytes::slices`] depending /// on their needs. /// /// To directly access raw data as contiguous slice it is preferred to convert `ZBytes` into a [`std::borrow::Cow<[u8]>`]. @@ -215,7 +215,7 @@ pub trait Deserialize { /// /// let buf: Vec = vec![0, 1, 2, 3]; /// let bytes = ZBytes::from(buf.clone()); -/// for slice in bytes.iter_raw() { +/// for slice in bytes.slices() { /// println!("{:02x?}", slice); /// } /// ``` @@ -298,7 +298,7 @@ impl ZBytes { /// Please note that no guarantee is provided on the internal memory layout of [`ZBytes`]. /// The only provided guarantee is on the bytes order that is preserved. /// - /// Please note that [`ZBytes::iter`] will perform deserialization while iterating while [`ZBytes::iter_raw`] will not. + /// Please note that [`ZBytes::iter`] will perform deserialization while iterating while [`ZBytes::slices`] will not. /// /// ```rust /// use std::io::Write; @@ -312,19 +312,19 @@ impl ZBytes { /// writer.write(&buf2); /// /// // Print the raw content - /// for slice in zbs.iter_raw() { + /// for slice in zbs.slices() { /// println!("{:02x?}", slice); /// } /// /// // Concatenate input in a single vector /// let buf: Vec = buf1.into_iter().chain(buf2.into_iter()).collect(); /// // Concatenate raw bytes in a single vector - /// let out: Vec = zbs.iter_raw().fold(Vec::new(), |mut b, x| { b.extend_from_slice(x); b }); + /// let out: Vec = zbs.slices().fold(Vec::new(), |mut b, x| { b.extend_from_slice(x); b }); /// // The previous line is the equivalent of /// // let out: Vec = zbs.into(); /// assert_eq!(buf, out); /// ``` - pub fn iter_raw(&self) -> impl Iterator { + pub fn slices(&self) -> impl Iterator { self.0.slices() } From 6cbcd34a121be500a7461290611b3aebef7c2897 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 4 Sep 2024 12:51:00 +0200 Subject: [PATCH 03/17] Fix typos --- zenoh/src/api/bytes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index 7df78728ab..e0dcef9956 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -192,7 +192,7 @@ pub trait Deserialize { /// /// To directly access raw data as contiguous slice it is preferred to convert `ZBytes` into a [`std::borrow::Cow<[u8]>`]. /// If `ZBytes` contains all the data in a single memory location, this is guaranteed to be zero-copy. This is the common case for small messages. -/// If `ZBytes` contains data scattered in differnt memory regions, this operation will do an allocation and a copy. This is the common case for large messages. +/// If `ZBytes` contains data scattered in different memory regions, this operation will do an allocation and a copy. This is the common case for large messages. /// /// Example: /// ```rust From f09a20fc68aaf5a75d0e8ee3b6f908c38c50c809 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 4 Sep 2024 15:33:12 +0200 Subject: [PATCH 04/17] Improve ZBytes docs --- zenoh/src/api/bytes.rs | 68 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index e0dcef9956..6197435e6e 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -263,6 +263,8 @@ impl ZBytes { } /// Get a [`ZBytesWriter`] implementing [`std::io::Write`] trait. + /// + /// See [`ZBytesWriter`] on how to chain the serialization of differnt types into a single [`ZBytes`]. pub fn writer(&mut self) -> ZBytesWriter<'_> { ZBytesWriter(self.0.writer()) } @@ -311,7 +313,7 @@ impl ZBytes { /// writer.write(&buf1); /// writer.write(&buf2); /// - /// // Print the raw content + /// // Access the raw content /// for slice in zbs.slices() { /// println!("{:02x?}", slice); /// } @@ -322,7 +324,26 @@ impl ZBytes { /// let out: Vec = zbs.slices().fold(Vec::new(), |mut b, x| { b.extend_from_slice(x); b }); /// // The previous line is the equivalent of /// // let out: Vec = zbs.into(); - /// assert_eq!(buf, out); + /// assert_eq!(buf, out); + /// ``` + /// + /// The example below shows how the [`ZBytesWriter::append`] simply appends the slices of one [`ZBytes`] + /// to another and how those slices can be iterated over to access the raw data. + /// ```rust + /// use std::io::Write; + /// use zenoh::bytes::ZBytes; + /// + /// let buf1: Vec = vec![1, 2, 3]; + /// let buf2: Vec = vec![4, 5, 6, 7, 8]; + /// + /// let mut zbs = ZBytes::empty(); + /// let mut writer = zbs.writer(); + /// writer.append(ZBytes::from(buf1.clone())); + /// writer.append(ZBytes::from(buf2.clone())); + /// + /// let mut iter = zbs.slices(); + /// assert_eq!(buf1.as_slice(), iter.next().unwrap()); + /// assert_eq!(buf2.as_slice(), iter.next().unwrap()); /// ``` pub fn slices(&self) -> impl Iterator { self.0.slices() @@ -376,9 +397,11 @@ impl ZBytes { ZSerde.serialize(t) } - /// Deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Deserialize an object of type `T` using [`ZSerde`]. + /// + /// See [`ZBytes::serialize`] and [`ZBytes::try_serialize`] for the examples. /// - /// The most efficient to retrieve a contiguous view o + /// See [`ZBytes::into`] for infallible conversion, e.g. to get raw bytes. pub fn deserialize<'a, T>(&'a self) -> Result>::Error> where ZSerde: Deserialize = &'a ZBytes>, @@ -387,7 +410,7 @@ impl ZBytes { ZSerde.deserialize(self) } - /// Deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Deserialize an object of type `T` using [`ZSerde`]. pub fn deserialize_mut<'a, T>(&'a mut self) -> Result>::Error> where ZSerde: Deserialize = &'a mut ZBytes>, @@ -396,7 +419,37 @@ impl ZBytes { ZSerde.deserialize(self) } - /// Infallibly deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Infallibly deserialize an object of type `T` using [`ZSerde`]. + /// + /// To directly access raw data as contiguous slice it is preferred to convert `ZBytes` into a [`std::borrow::Cow<[u8]>`](`std::borrow::Cow`). + /// If [`ZBytes`] contains all the data in a single memory location, then it is guaranteed to be zero-copy. This is the common case for small messages. + /// If [`ZBytes`] contains data scattered in different memory regions, this operation will do an allocation and a copy. This is the common case for large messages. + /// + /// ```rust + /// use std::borrow::Cow; + /// use zenoh::bytes::ZBytes; + /// + /// let buf: Vec = vec![0, 1, 2, 3]; + /// let bytes = ZBytes::from(buf.clone()); + /// let deser: Cow<[u8]> = bytes.into(); + /// assert_eq!(buf.as_slice(), deser.as_ref()); + /// ``` + /// + /// An alternative is to convert `ZBytes` into a [`std::vec::Vec`]. + /// Converting to [`std::vec::Vec`] will always allocate and make a copy. + /// + /// ```rust + /// use std::borrow::Cow; + /// use zenoh::bytes::ZBytes; + /// + /// let buf: Vec = vec![0, 1, 2, 3]; + /// let bytes = ZBytes::from(buf.clone()); + /// let deser: Vec = bytes.into(); + /// assert_eq!(buf.as_slice(), deser.as_slice()); + /// ``` + /// + /// If you want to be sure that no copy is performed at all, then you should use [`ZBytes::slices`]. + /// Please note that in this case data may not be contiguous in memory and it is the responsability of the user to properly parse the raw slices. pub fn into<'a, T>(&'a self) -> T where ZSerde: Deserialize = &'a ZBytes, Error = Infallible>, @@ -405,7 +458,7 @@ impl ZBytes { ZSerde.deserialize(self).unwrap_infallible() } - /// Infallibly deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Infallibly deserialize an object of type `T` using the [`ZSerde`]. pub fn into_mut<'a, T>(&'a mut self) -> T where ZSerde: Deserialize = &'a mut ZBytes, Error = Infallible>, @@ -1249,6 +1302,7 @@ impl From<&mut Cow<'_, str>> for ZBytes { } } +/// See [`Deserialize>`] for guarantees on copies. impl<'a> Deserialize> for ZSerde { type Input<'b> = &'a ZBytes; type Error = Utf8Error; From f8a7576fc6bed60bafeb8dff314d894814391594 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 4 Sep 2024 15:33:12 +0200 Subject: [PATCH 05/17] Improve ZBytes docs --- zenoh/src/api/bytes.rs | 72 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 9 deletions(-) diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index e0dcef9956..476f440512 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -242,7 +242,7 @@ impl ZBytes { self.0.is_empty() } - /// Returns the length of the ZBytes. + /// Returns the total number of bytes in the ZBytes. pub fn len(&self) -> usize { self.0.len() } @@ -263,6 +263,8 @@ impl ZBytes { } /// Get a [`ZBytesWriter`] implementing [`std::io::Write`] trait. + /// + /// See [`ZBytesWriter`] on how to chain the serialization of differnt types into a single [`ZBytes`]. pub fn writer(&mut self) -> ZBytesWriter<'_> { ZBytesWriter(self.0.writer()) } @@ -311,7 +313,7 @@ impl ZBytes { /// writer.write(&buf1); /// writer.write(&buf2); /// - /// // Print the raw content + /// // Access the raw content /// for slice in zbs.slices() { /// println!("{:02x?}", slice); /// } @@ -322,7 +324,26 @@ impl ZBytes { /// let out: Vec = zbs.slices().fold(Vec::new(), |mut b, x| { b.extend_from_slice(x); b }); /// // The previous line is the equivalent of /// // let out: Vec = zbs.into(); - /// assert_eq!(buf, out); + /// assert_eq!(buf, out); + /// ``` + /// + /// The example below shows how the [`ZBytesWriter::append`] simply appends the slices of one [`ZBytes`] + /// to another and how those slices can be iterated over to access the raw data. + /// ```rust + /// use std::io::Write; + /// use zenoh::bytes::ZBytes; + /// + /// let buf1: Vec = vec![1, 2, 3]; + /// let buf2: Vec = vec![4, 5, 6, 7, 8]; + /// + /// let mut zbs = ZBytes::empty(); + /// let mut writer = zbs.writer(); + /// writer.append(ZBytes::from(buf1.clone())); + /// writer.append(ZBytes::from(buf2.clone())); + /// + /// let mut iter = zbs.slices(); + /// assert_eq!(buf1.as_slice(), iter.next().unwrap()); + /// assert_eq!(buf2.as_slice(), iter.next().unwrap()); /// ``` pub fn slices(&self) -> impl Iterator { self.0.slices() @@ -376,9 +397,11 @@ impl ZBytes { ZSerde.serialize(t) } - /// Deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Deserialize an object of type `T` using [`ZSerde`]. + /// + /// See [`ZBytes::serialize`] and [`ZBytes::try_serialize`] for the examples. /// - /// The most efficient to retrieve a contiguous view o + /// See [`ZBytes::into`] for infallible conversion, e.g. to get raw bytes. pub fn deserialize<'a, T>(&'a self) -> Result>::Error> where ZSerde: Deserialize = &'a ZBytes>, @@ -387,7 +410,7 @@ impl ZBytes { ZSerde.deserialize(self) } - /// Deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Deserialize an object of type `T` using [`ZSerde`]. pub fn deserialize_mut<'a, T>(&'a mut self) -> Result>::Error> where ZSerde: Deserialize = &'a mut ZBytes>, @@ -396,7 +419,37 @@ impl ZBytes { ZSerde.deserialize(self) } - /// Infallibly deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Infallibly deserialize an object of type `T` using [`ZSerde`]. + /// + /// To directly access raw data as contiguous slice it is preferred to convert `ZBytes` into a [`std::borrow::Cow<[u8]>`](`std::borrow::Cow`). + /// If [`ZBytes`] contains all the data in a single memory location, then it is guaranteed to be zero-copy. This is the common case for small messages. + /// If [`ZBytes`] contains data scattered in different memory regions, this operation will do an allocation and a copy. This is the common case for large messages. + /// + /// ```rust + /// use std::borrow::Cow; + /// use zenoh::bytes::ZBytes; + /// + /// let buf: Vec = vec![0, 1, 2, 3]; + /// let bytes = ZBytes::from(buf.clone()); + /// let deser: Cow<[u8]> = bytes.into(); + /// assert_eq!(buf.as_slice(), deser.as_ref()); + /// ``` + /// + /// An alternative is to convert `ZBytes` into a [`std::vec::Vec`]. + /// Converting to [`std::vec::Vec`] will always allocate and make a copy. + /// + /// ```rust + /// use std::borrow::Cow; + /// use zenoh::bytes::ZBytes; + /// + /// let buf: Vec = vec![0, 1, 2, 3]; + /// let bytes = ZBytes::from(buf.clone()); + /// let deser: Vec = bytes.into(); + /// assert_eq!(buf.as_slice(), deser.as_slice()); + /// ``` + /// + /// If you want to be sure that no copy is performed at all, then you should use [`ZBytes::slices`]. + /// Please note that in this case data may not be contiguous in memory and it is the responsability of the user to properly parse the raw slices. pub fn into<'a, T>(&'a self) -> T where ZSerde: Deserialize = &'a ZBytes, Error = Infallible>, @@ -405,7 +458,7 @@ impl ZBytes { ZSerde.deserialize(self).unwrap_infallible() } - /// Infallibly deserialize an object of type `T` from a [`Value`] using the [`ZSerde`]. + /// Infallibly deserialize an object of type `T` using the [`ZSerde`]. pub fn into_mut<'a, T>(&'a mut self) -> T where ZSerde: Deserialize = &'a mut ZBytes, Error = Infallible>, @@ -638,7 +691,7 @@ where } /// The default serializer for [`ZBytes`]. It supports primitives types, such as: `Vec`, `uX`, `iX`, `fX`, `String`, `bool`. -/// It also supports common Rust serde values like `serde_json::Value`. +/// It also supports common Rust serde values like [`serde_json::Value`]. /// /// **NOTE:** Zenoh semantic and protocol take care of sending and receiving bytes without restricting the actual data types. /// [`ZSerde`] is the default serializer/deserializer provided for convenience to the users to deal with primitives data types via @@ -1249,6 +1302,7 @@ impl From<&mut Cow<'_, str>> for ZBytes { } } +/// See [`Deserialize>`] for guarantees on copies. impl<'a> Deserialize> for ZSerde { type Input<'b> = &'a ZBytes; type Error = Utf8Error; From 7b5f9ae03ca059e425009b91b89dbf42db85d506 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 4 Sep 2024 15:53:07 +0200 Subject: [PATCH 06/17] Fix typos --- zenoh/src/api/bytes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index 476f440512..9595a70d23 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -264,7 +264,7 @@ impl ZBytes { /// Get a [`ZBytesWriter`] implementing [`std::io::Write`] trait. /// - /// See [`ZBytesWriter`] on how to chain the serialization of differnt types into a single [`ZBytes`]. + /// See [`ZBytesWriter`] on how to chain the serialization of different types into a single [`ZBytes`]. pub fn writer(&mut self) -> ZBytesWriter<'_> { ZBytesWriter(self.0.writer()) } @@ -449,7 +449,7 @@ impl ZBytes { /// ``` /// /// If you want to be sure that no copy is performed at all, then you should use [`ZBytes::slices`]. - /// Please note that in this case data may not be contiguous in memory and it is the responsability of the user to properly parse the raw slices. + /// Please note that in this case data may not be contiguous in memory and it is the responsibility of the user to properly parse the raw slices. pub fn into<'a, T>(&'a self) -> T where ZSerde: Deserialize = &'a ZBytes, Error = Infallible>, From ce153a1526fdca1979bc5c1e5bebdd721948ec8d Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Thu, 5 Sep 2024 09:25:54 +0000 Subject: [PATCH 07/17] Remove unused dependencies --- .github/workflows/ci.yml | 8 +- Cargo.lock | 153 ++---------------- Cargo.toml | 1 + ci/nostd-check/Cargo.toml | 4 + ci/valgrind-check/Cargo.toml | 2 - commons/zenoh-codec/Cargo.toml | 2 - commons/zenoh-collections/Cargo.toml | 3 +- commons/zenoh-config/Cargo.toml | 3 + commons/zenoh-core/Cargo.toml | 1 - commons/zenoh-protocol/Cargo.toml | 3 +- commons/zenoh-runtime/Cargo.toml | 5 +- commons/zenoh-shm/Cargo.toml | 4 +- commons/zenoh-sync/Cargo.toml | 1 - examples/Cargo.toml | 11 +- io/zenoh-link-commons/Cargo.toml | 8 +- io/zenoh-link/Cargo.toml | 2 - io/zenoh-links/zenoh-link-quic/Cargo.toml | 10 +- io/zenoh-links/zenoh-link-serial/Cargo.toml | 4 - io/zenoh-links/zenoh-link-tcp/Cargo.toml | 2 - io/zenoh-links/zenoh-link-tls/Cargo.toml | 7 +- io/zenoh-links/zenoh-link-udp/Cargo.toml | 2 - io/zenoh-links/zenoh-link-unixpipe/Cargo.toml | 2 - .../zenoh-link-unixsock_stream/Cargo.toml | 2 - io/zenoh-links/zenoh-link-vsock/Cargo.toml | 2 - io/zenoh-links/zenoh-link-ws/Cargo.toml | 1 - io/zenoh-transport/Cargo.toml | 1 - plugins/zenoh-backend-example/Cargo.toml | 6 +- plugins/zenoh-plugin-example/Cargo.toml | 4 +- plugins/zenoh-plugin-rest/Cargo.toml | 1 - .../zenoh-plugin-storage-manager/Cargo.toml | 7 +- plugins/zenoh-plugin-trait/Cargo.toml | 4 +- zenoh-ext/Cargo.toml | 3 - zenoh-ext/examples/Cargo.toml | 9 +- zenoh/Cargo.toml | 7 - 34 files changed, 58 insertions(+), 227 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e932f26bb1..d7f3f32150 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,9 @@ jobs: - name: Install latest cargo-deny uses: taiki-e/install-action@cargo-deny + - name: Install latest cargo-machete + uses: taiki-e/install-action@cargo-machete + - name: Code format check run: cargo fmt --check -- --config "unstable_features=true,imports_granularity=Crate,group_imports=StdExternalCrate" @@ -94,6 +97,9 @@ jobs: - name: Check licenses run: cargo deny check licenses + - name: Check unused dependencies + run: cargo machete + test: name: Unit tests on ${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -179,4 +185,4 @@ jobs: if: always() steps: - name: Check whether all jobs pass - run: echo '${{ toJson(needs) }}' | jq -e 'all(.result == "success")' \ No newline at end of file + run: echo '${{ toJson(needs) }}' | jq -e 'all(.result == "success")' diff --git a/Cargo.lock b/Cargo.lock index 2f140121fa..aac8c0c10f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -333,7 +333,6 @@ dependencies = [ "blocking", "futures-lite 2.0.0", "once_cell", - "tokio", ] [[package]] @@ -1817,7 +1816,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite 0.2.13", - "socket2 0.4.9", + "socket2 0.5.7", "tokio", "tower-service", "tracing", @@ -2154,7 +2153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f56d36f573486ba7f462b62cbae597fef7d5d93665e7047956b457531b8a1ced" dependencies = [ "prost 0.11.9", - "prost-types 0.11.9", + "prost-types", ] [[package]] @@ -2669,16 +2668,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "pem" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" -dependencies = [ - "base64 0.22.1", - "serde", -] - [[package]] name = "pem-rfc7468" version = "0.7.0" @@ -3017,12 +3006,12 @@ dependencies = [ [[package]] name = "prost" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc" +checksum = "3b2ecbe40f08db5c006b5764a2645f7f3f141ce756412ac9e1dd6087e6d32995" dependencies = [ "bytes", - "prost-derive 0.13.1", + "prost-derive 0.13.2", ] [[package]] @@ -3040,9 +3029,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18bec9b0adc4eba778b33684b7ba3e7137789434769ee3ce3930463ef904cfca" +checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" dependencies = [ "anyhow", "itertools 0.13.0", @@ -3060,15 +3049,6 @@ dependencies = [ "prost 0.11.9", ] -[[package]] -name = "prost-types" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee5168b05f49d4b0ca581206eb14a7b22fafd963efe729ac48eb03266e25cc2" -dependencies = [ - "prost 0.13.1", -] - [[package]] name = "quinn" version = "0.11.3" @@ -3220,19 +3200,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "rcgen" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54077e1872c46788540de1ea3d7f4ccb1983d12f9aa909b234468676c1a36779" -dependencies = [ - "pem", - "ring", - "rustls-pki-types", - "time 0.3.36", - "yasna", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -4138,18 +4105,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" -[[package]] -name = "stop-token" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af91f480ee899ab2d9f8435bfdfc14d08a5754bd9d3fef1f1a1c23336aad6c8b" -dependencies = [ - "async-channel 1.9.0", - "cfg-if 1.0.0", - "futures-core", - "pin-project-lite 0.2.13", -] - [[package]] name = "strsim" version = "0.11.1" @@ -4745,7 +4700,7 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "static_assertions", ] @@ -4863,12 +4818,6 @@ dependencies = [ "serde", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "utf-8" version = "0.7.6" @@ -5368,15 +5317,6 @@ dependencies = [ "time 0.3.36", ] -[[package]] -name = "yasna" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" -dependencies = [ - "time 0.3.36", -] - [[package]] name = "z-serial" version = "0.2.3" @@ -5396,11 +5336,8 @@ version = "1.0.0-dev" dependencies = [ "ahash", "async-trait", - "base64 0.22.1", "bytes", - "event-listener 5.3.1", "flume", - "form_urlencoded", "futures", "git-version", "itertools 0.13.0", @@ -5411,7 +5348,6 @@ dependencies = [ "petgraph", "phf", "rand 0.8.5", - "regex", "rustc_version 0.4.1", "serde", "serde-pickle", @@ -5419,20 +5355,17 @@ dependencies = [ "serde_json", "serde_yaml", "socket2 0.5.7", - "stop-token", "tokio", "tokio-util", "tracing", "uhlc", "unwrap-infallible", - "uuid", "vec_map", "zenoh-buffers", "zenoh-codec", "zenoh-collections", "zenoh-config", "zenoh-core", - "zenoh-crypto", "zenoh-keyexpr", "zenoh-link", "zenoh-macros", @@ -5452,12 +5385,9 @@ name = "zenoh-backend-example" version = "1.0.0-dev" dependencies = [ "async-trait", - "const_format", - "futures", "git-version", "serde_json", "tokio", - "tracing", "zenoh", "zenoh-plugin-trait", "zenoh_backend_traits", @@ -5477,7 +5407,6 @@ version = "1.0.0-dev" dependencies = [ "criterion", "rand 0.8.5", - "serde", "tracing", "uhlc", "zenoh-buffers", @@ -5489,9 +5418,6 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "1.0.0-dev" -dependencies = [ - "rand 0.8.5", -] [[package]] name = "zenoh-config" @@ -5518,7 +5444,6 @@ dependencies = [ name = "zenoh-core" version = "1.0.0-dev" dependencies = [ - "async-global-executor", "lazy_static", "tokio", "zenoh-result", @@ -5542,22 +5467,15 @@ name = "zenoh-examples" version = "1.0.0-dev" dependencies = [ "clap", - "flume", "futures", - "git-version", - "json5", - "prost 0.13.1", - "prost-types 0.13.1", + "prost 0.13.2", "rand 0.8.5", "rustc_version 0.4.1", "serde_json", "serde_yaml", "tokio", - "tracing", "zenoh", - "zenoh-collections", "zenoh-ext", - "zenoh-util", ] [[package]] @@ -5567,10 +5485,7 @@ dependencies = [ "bincode", "flume", "futures", - "phf", "serde", - "serde_cbor", - "serde_json", "tokio", "tracing", "zenoh", @@ -5582,16 +5497,11 @@ dependencies = [ name = "zenoh-ext-examples" version = "1.0.0-dev" dependencies = [ - "bincode", "clap", - "flume", "futures", - "serde", "tokio", - "tracing", "zenoh", "zenoh-ext", - "zenoh-util", ] [[package]] @@ -5614,8 +5524,6 @@ dependencies = [ name = "zenoh-link" version = "1.0.0-dev" dependencies = [ - "async-trait", - "rcgen", "zenoh-config", "zenoh-link-commons", "zenoh-link-quic", @@ -5636,7 +5544,6 @@ name = "zenoh-link-commons" version = "1.0.0-dev" dependencies = [ "async-trait", - "base64 0.22.1", "flume", "futures", "rustls", @@ -5645,10 +5552,8 @@ dependencies = [ "tokio", "tokio-util", "tracing", - "webpki-roots", "zenoh-buffers", "zenoh-codec", - "zenoh-config", "zenoh-core", "zenoh-protocol", "zenoh-result", @@ -5662,7 +5567,6 @@ version = "1.0.0-dev" dependencies = [ "async-trait", "base64 0.22.1", - "futures", "quinn", "rustls", "rustls-pemfile 2.1.3", @@ -5670,20 +5574,15 @@ dependencies = [ "rustls-webpki", "secrecy", "tokio", - "tokio-rustls", "tokio-util", "tracing", "webpki-roots", "x509-parser", - "zenoh-collections", "zenoh-config", "zenoh-core", "zenoh-link-commons", "zenoh-protocol", "zenoh-result", - "zenoh-runtime", - "zenoh-sync", - "zenoh-util", ] [[package]] @@ -5691,20 +5590,16 @@ name = "zenoh-link-serial" version = "1.0.0-dev" dependencies = [ "async-trait", - "futures", "tokio", "tokio-util", "tracing", "uuid", "z-serial", - "zenoh-collections", "zenoh-core", "zenoh-link-commons", "zenoh-protocol", "zenoh-result", "zenoh-runtime", - "zenoh-sync", - "zenoh-util", ] [[package]] @@ -5720,8 +5615,6 @@ dependencies = [ "zenoh-link-commons", "zenoh-protocol", "zenoh-result", - "zenoh-runtime", - "zenoh-sync", "zenoh-util", ] @@ -5731,7 +5624,6 @@ version = "1.0.0-dev" dependencies = [ "async-trait", "base64 0.22.1", - "futures", "rustls", "rustls-pemfile 2.1.3", "rustls-pki-types", @@ -5744,15 +5636,12 @@ dependencies = [ "tracing", "webpki-roots", "x509-parser", - "zenoh-collections", "zenoh-config", "zenoh-core", "zenoh-link-commons", "zenoh-protocol", "zenoh-result", "zenoh-runtime", - "zenoh-sync", - "zenoh-util", ] [[package]] @@ -5765,12 +5654,10 @@ dependencies = [ "tokio-util", "tracing", "zenoh-buffers", - "zenoh-collections", "zenoh-core", "zenoh-link-commons", "zenoh-protocol", "zenoh-result", - "zenoh-runtime", "zenoh-sync", "zenoh-util", ] @@ -5788,8 +5675,6 @@ dependencies = [ "tokio-util", "tracing", "unix-named-pipe", - "zenoh-buffers", - "zenoh-collections", "zenoh-config", "zenoh-core", "zenoh-link-commons", @@ -5803,7 +5688,6 @@ name = "zenoh-link-unixsock_stream" version = "1.0.0-dev" dependencies = [ "async-trait", - "futures", "nix 0.29.0", "tokio", "tokio-util", @@ -5814,7 +5698,6 @@ dependencies = [ "zenoh-protocol", "zenoh-result", "zenoh-runtime", - "zenoh-sync", ] [[package]] @@ -5832,8 +5715,6 @@ dependencies = [ "zenoh-protocol", "zenoh-result", "zenoh-runtime", - "zenoh-sync", - "zenoh-util", ] [[package]] @@ -5852,7 +5733,6 @@ dependencies = [ "zenoh-protocol", "zenoh-result", "zenoh-runtime", - "zenoh-sync", "zenoh-util", ] @@ -5870,7 +5750,6 @@ dependencies = [ name = "zenoh-plugin-example" version = "1.0.0-dev" dependencies = [ - "const_format", "futures", "git-version", "lazy_static", @@ -5889,7 +5768,6 @@ dependencies = [ "anyhow", "base64 0.22.1", "clap", - "const_format", "flume", "futures", "git-version", @@ -5913,7 +5791,6 @@ version = "1.0.0-dev" dependencies = [ "async-global-executor", "async-trait", - "const_format", "crc", "derive-new", "flume", @@ -5921,17 +5798,14 @@ dependencies = [ "git-version", "jsonschema", "lazy_static", - "libloading", "rustc_version 0.4.1", "schemars", "serde", "serde_json", "tokio", "tracing", - "urlencoding", "zenoh", "zenoh-plugin-trait", - "zenoh-util", "zenoh_backend_traits", ] @@ -5939,9 +5813,9 @@ dependencies = [ name = "zenoh-plugin-trait" version = "1.0.0-dev" dependencies = [ + "git-version", "libloading", "serde", - "serde_json", "tracing", "zenoh-keyexpr", "zenoh-macros", @@ -5959,7 +5833,6 @@ dependencies = [ "serde", "uhlc", "zenoh-buffers", - "zenoh-collections", "zenoh-keyexpr", "zenoh-result", ] @@ -5975,9 +5848,7 @@ dependencies = [ name = "zenoh-runtime" version = "1.0.0-dev" dependencies = [ - "futures", "lazy_static", - "libc", "ron", "serde", "tokio", @@ -5990,14 +5861,12 @@ name = "zenoh-shm" version = "1.0.0-dev" dependencies = [ "async-trait", - "bincode", "crc", "libc", "lockfree", "num-traits", "num_cpus", "rand 0.8.5", - "serde", "shared_memory", "stabby", "static_init", @@ -6021,7 +5890,6 @@ dependencies = [ "zenoh-collections", "zenoh-core", "zenoh-result", - "zenoh-runtime", ] [[package]] @@ -6058,7 +5926,6 @@ dependencies = [ "tracing", "zenoh-buffers", "zenoh-codec", - "zenoh-collections", "zenoh-config", "zenoh-core", "zenoh-crypto", diff --git a/Cargo.toml b/Cargo.toml index 484baaaef0..cb836bb14a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -189,6 +189,7 @@ winapi = { version = "0.3.9", features = ["iphlpapi", "winerror"] } x509-parser = "0.16.0" z-serial = "0.2.3" either = "1.13.0" +prost = "0.13.1" zenoh-ext = { version = "1.0.0-dev", path = "zenoh-ext" } zenoh-shm = { version = "1.0.0-dev", path = "commons/zenoh-shm" } zenoh-result = { version = "1.0.0-dev", path = "commons/zenoh-result", default-features = false } diff --git a/ci/nostd-check/Cargo.toml b/ci/nostd-check/Cargo.toml index 732b0969d2..80453b293a 100644 --- a/ci/nostd-check/Cargo.toml +++ b/ci/nostd-check/Cargo.toml @@ -29,6 +29,10 @@ zenoh-buffers = { path = "../../commons/zenoh-buffers/", default-features = fals zenoh-codec = { path = "../../commons/zenoh-codec/", default-features = false } zenoh-protocol = { path = "../../commons/zenoh-protocol/", default-features = false } + [[bin]] name = "nostd_check" path = "src/bin/nostd_check.rs" + +[package.metadata.cargo-machete] +ignored = ["zenoh-buffers", "zenoh-codec", "zenoh-protocol"] \ No newline at end of file diff --git a/ci/valgrind-check/Cargo.toml b/ci/valgrind-check/Cargo.toml index 94ee27e7eb..efee6feaec 100644 --- a/ci/valgrind-check/Cargo.toml +++ b/ci/valgrind-check/Cargo.toml @@ -23,8 +23,6 @@ description = "Internal crate for zenoh." [dependencies] tokio = { version = "1.35.1", features = ["rt-multi-thread", "time", "io-std"] } -tracing-subscriber = { version = "0.3", features = ["json", "env-filter"] } -futures = "0.3.25" zenoh = { path = "../../zenoh/" } zenoh-runtime = { path = "../../commons/zenoh-runtime/" } zenoh-util = { path = "../../commons/zenoh-util/", features = ["test"] } diff --git a/commons/zenoh-codec/Cargo.toml b/commons/zenoh-codec/Cargo.toml index 209a4c698d..bafff7da60 100644 --- a/commons/zenoh-codec/Cargo.toml +++ b/commons/zenoh-codec/Cargo.toml @@ -32,7 +32,6 @@ description = "Internal crate for zenoh." default = ["std"] std = [ "tracing", - "serde/std", "uhlc/std", "zenoh-protocol/std" ] @@ -45,7 +44,6 @@ shared-memory = [ [dependencies] tracing = {workspace = true, optional = true } -serde = { workspace = true, features = ["alloc"] } uhlc = { workspace = true } zenoh-buffers = { workspace = true, default-features = false } zenoh-protocol = { workspace = true } diff --git a/commons/zenoh-collections/Cargo.toml b/commons/zenoh-collections/Cargo.toml index 27787e8c6a..8a7f2d795b 100644 --- a/commons/zenoh-collections/Cargo.toml +++ b/commons/zenoh-collections/Cargo.toml @@ -31,7 +31,6 @@ description = "Internal crate for zenoh." [features] default = ["std"] std = [] -test = ["rand"] +test = [] [dependencies] -rand = { workspace = true, optional = true } diff --git a/commons/zenoh-config/Cargo.toml b/commons/zenoh-config/Cargo.toml index 49c9d722f1..2bd4c83211 100644 --- a/commons/zenoh-config/Cargo.toml +++ b/commons/zenoh-config/Cargo.toml @@ -42,3 +42,6 @@ zenoh-util = { workspace = true } zenoh-macros = { workspace = true } secrecy = { workspace = true } uhlc = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["tracing"] diff --git a/commons/zenoh-core/Cargo.toml b/commons/zenoh-core/Cargo.toml index 7890646d1b..f9c5fdb58d 100644 --- a/commons/zenoh-core/Cargo.toml +++ b/commons/zenoh-core/Cargo.toml @@ -33,7 +33,6 @@ default = ["std"] [dependencies] tokio = { workspace = true, features = ["rt"] } -async-global-executor = { workspace = true, features = ["tokio"] } lazy_static = { workspace = true } zenoh-result = { workspace = true } zenoh-runtime = { workspace = true } diff --git a/commons/zenoh-protocol/Cargo.toml b/commons/zenoh-protocol/Cargo.toml index 2c3a36b7a7..9d7e35d690 100644 --- a/commons/zenoh-protocol/Cargo.toml +++ b/commons/zenoh-protocol/Cargo.toml @@ -33,7 +33,7 @@ std = [ "zenoh-keyexpr/std", "zenoh-result/std", ] -test = ["rand", "zenoh-buffers/test", "zenoh-collections/test"] +test = ["rand", "zenoh-buffers/test"] shared-memory = ["std", "zenoh-buffers/shared-memory"] stats = [] @@ -43,7 +43,6 @@ rand = { workspace = true, features = ["alloc", "getrandom"], optional = true } serde = { workspace = true, features = ["alloc"] } uhlc = { workspace = true, default-features = false } zenoh-buffers = { workspace = true, default-features = false } -zenoh-collections = { workspace = true, default-features = false } zenoh-keyexpr = { workspace = true } zenoh-result = { workspace = true } diff --git a/commons/zenoh-runtime/Cargo.toml b/commons/zenoh-runtime/Cargo.toml index bfc1a8ffb5..4ab501f109 100644 --- a/commons/zenoh-runtime/Cargo.toml +++ b/commons/zenoh-runtime/Cargo.toml @@ -13,11 +13,12 @@ description = { workspace = true } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -libc = { workspace = true } ron = { workspace = true } serde = { workspace = true } -futures = { workspace = true } lazy_static = { workspace = true } tokio = { workspace = true, features = ["fs", "io-util", "macros", "net", "rt-multi-thread", "sync", "time"] } zenoh-result = { workspace = true, features = ["std"] } zenoh-macros = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["ron"] \ No newline at end of file diff --git a/commons/zenoh-shm/Cargo.toml b/commons/zenoh-shm/Cargo.toml index e5eb204a23..0b79fd2549 100644 --- a/commons/zenoh-shm/Cargo.toml +++ b/commons/zenoh-shm/Cargo.toml @@ -33,10 +33,8 @@ test = ["num_cpus"] [dependencies] async-trait = { workspace = true } -bincode = { workspace = true } crc = { workspace = true } tracing = { workspace = true } -serde = { workspace = true, features = ["default"] } shared_memory = { workspace = true } tokio = { workspace = true } zenoh-result = { workspace = true } @@ -52,4 +50,4 @@ lockfree = { workspace = true } stabby = { workspace = true } [dev-dependencies] -libc = { workspace = true } \ No newline at end of file +libc = { workspace = true } diff --git a/commons/zenoh-sync/Cargo.toml b/commons/zenoh-sync/Cargo.toml index 01e8e935fd..8124a184e7 100644 --- a/commons/zenoh-sync/Cargo.toml +++ b/commons/zenoh-sync/Cargo.toml @@ -35,7 +35,6 @@ tokio = { workspace = true, features = ["sync"] } zenoh-buffers = { workspace = true } zenoh-collections = { workspace = true, features = ["default"] } zenoh-core = { workspace = true } -zenoh-runtime = { workspace = true } [dev-dependencies] tokio = { workspace = true, features = ["macros", "sync", "rt-multi-thread", "time"] } diff --git a/examples/Cargo.toml b/examples/Cargo.toml index c2fb23aca3..0d8aee48f5 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -34,19 +34,12 @@ transport_unixpipe = ["zenoh/transport_unixpipe"] [dependencies] tokio = { workspace = true, features = ["rt-multi-thread", "time", "io-std"] } clap = { workspace = true, features = ["derive"] } -zenoh-util = { workspace = true } -flume = { workspace = true } futures = { workspace = true } -git-version = { workspace = true } -json5 = { workspace = true } -zenoh-collections = { workspace = true } -tracing = { workspace = true } zenoh = { workspace = true, default-features = true } -zenoh-ext = { workspace = true } serde_json = { workspace = true } serde_yaml = { workspace = true } -prost = "0.13.1" -prost-types = "0.13.1" +prost = { workspace = true } +zenoh-ext = { workspace = true } [dev-dependencies] rand = { workspace = true, features = ["default"] } diff --git a/io/zenoh-link-commons/Cargo.toml b/io/zenoh-link-commons/Cargo.toml index 7ec7c533d7..5f8f91aa61 100644 --- a/io/zenoh-link-commons/Cargo.toml +++ b/io/zenoh-link-commons/Cargo.toml @@ -26,11 +26,10 @@ version = { workspace = true } [features] compression = [] -tls = ["dep:rustls", "dep:rustls-webpki", "dep:webpki-roots"] +tls = ["dep:rustls", "dep:rustls-webpki"] [dependencies] async-trait = { workspace = true } -base64 = { workspace = true, optional = true } flume = { workspace = true } futures = { workspace = true } rustls = { workspace = true, optional = true } @@ -45,12 +44,13 @@ tokio = { workspace = true, features = [ ] } tokio-util = { workspace = true, features = ["rt"] } tracing = { workspace = true } -webpki-roots = { workspace = true, optional = true } zenoh-buffers = { workspace = true } zenoh-codec = { workspace = true } -zenoh-config = { workspace = true } zenoh-core = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } zenoh-runtime = { workspace = true } zenoh-util = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["rustls-webpki"] \ No newline at end of file diff --git a/io/zenoh-link/Cargo.toml b/io/zenoh-link/Cargo.toml index 7a9772391f..64f0dc053e 100644 --- a/io/zenoh-link/Cargo.toml +++ b/io/zenoh-link/Cargo.toml @@ -36,8 +36,6 @@ transport_unixpipe = ["zenoh-link-unixpipe", "zenoh-link-unixpipe/transport_unix transport_vsock = ["zenoh-link-vsock"] [dependencies] -async-trait = { workspace = true } -rcgen = { workspace = true, optional = true } zenoh-config = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-link-quic = { workspace = true, optional = true } diff --git a/io/zenoh-links/zenoh-link-quic/Cargo.toml b/io/zenoh-links/zenoh-link-quic/Cargo.toml index ff634d9d15..b01f5e4261 100644 --- a/io/zenoh-links/zenoh-link-quic/Cargo.toml +++ b/io/zenoh-links/zenoh-link-quic/Cargo.toml @@ -27,7 +27,6 @@ version = { workspace = true } [dependencies] async-trait = { workspace = true } base64 = { workspace = true } -futures = { workspace = true } quinn = { workspace = true } rustls = { workspace = true } rustls-pemfile = { workspace = true } @@ -41,17 +40,16 @@ tokio = { workspace = true, features = [ "sync", "time", ] } -tokio-rustls = { workspace = true } +# tokio-rustls = { workspace = true } tokio-util = { workspace = true, features = ["rt"] } tracing = { workspace = true } webpki-roots = { workspace = true } x509-parser = { workspace = true } -zenoh-collections = { workspace = true } zenoh-config = { workspace = true } zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true, features = ["tls"] } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } -zenoh-runtime = { workspace = true } -zenoh-sync = { workspace = true } -zenoh-util = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["rustls-webpki"] \ No newline at end of file diff --git a/io/zenoh-links/zenoh-link-serial/Cargo.toml b/io/zenoh-links/zenoh-link-serial/Cargo.toml index d89e1a0e78..0f8a02a445 100644 --- a/io/zenoh-links/zenoh-link-serial/Cargo.toml +++ b/io/zenoh-links/zenoh-link-serial/Cargo.toml @@ -33,17 +33,13 @@ description = "Internal crate for zenoh." [dependencies] async-trait = { workspace = true } -futures = { workspace = true } tracing = {workspace = true} tokio = { workspace = true, features = ["io-std", "macros", "net", "rt-multi-thread", "time"] } tokio-util = { workspace = true, features = ["rt"] } uuid = { workspace = true, default-features = true } z-serial = { workspace = true } -zenoh-collections = { workspace = true } zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } -zenoh-sync = { workspace = true } -zenoh-util = { workspace = true } zenoh-runtime = { workspace = true } diff --git a/io/zenoh-links/zenoh-link-tcp/Cargo.toml b/io/zenoh-links/zenoh-link-tcp/Cargo.toml index 4a501f61ed..8a631bdfbc 100644 --- a/io/zenoh-links/zenoh-link-tcp/Cargo.toml +++ b/io/zenoh-links/zenoh-link-tcp/Cargo.toml @@ -34,6 +34,4 @@ zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } -zenoh-sync = { workspace = true } zenoh-util = { workspace = true } -zenoh-runtime = { workspace = true } diff --git a/io/zenoh-links/zenoh-link-tls/Cargo.toml b/io/zenoh-links/zenoh-link-tls/Cargo.toml index 3bd357d1e4..5bd45a4463 100644 --- a/io/zenoh-links/zenoh-link-tls/Cargo.toml +++ b/io/zenoh-links/zenoh-link-tls/Cargo.toml @@ -27,7 +27,6 @@ version = { workspace = true } [dependencies] async-trait = { workspace = true } base64 = { workspace = true } -futures = { workspace = true } rustls = { workspace = true } rustls-pemfile = { workspace = true } rustls-pki-types = { workspace = true } @@ -40,12 +39,12 @@ tokio-util = { workspace = true, features = ["rt"] } tracing = { workspace = true } x509-parser = { workspace = true } webpki-roots = { workspace = true } -zenoh-collections = { workspace = true } zenoh-config = { workspace = true } zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true, features = ["tls"] } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } zenoh-runtime = { workspace = true } -zenoh-sync = { workspace = true } -zenoh-util = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["rustls-webpki"] \ No newline at end of file diff --git a/io/zenoh-links/zenoh-link-udp/Cargo.toml b/io/zenoh-links/zenoh-link-udp/Cargo.toml index f1bc3365f1..0e4b35f561 100644 --- a/io/zenoh-links/zenoh-link-udp/Cargo.toml +++ b/io/zenoh-links/zenoh-link-udp/Cargo.toml @@ -31,11 +31,9 @@ async-trait = { workspace = true } tracing = {workspace = true} socket2 = { workspace = true } zenoh-buffers = { workspace = true } -zenoh-collections = { workspace = true } zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } zenoh-sync = { workspace = true } zenoh-util = { workspace = true } -zenoh-runtime = { workspace = true } diff --git a/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml b/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml index b52bdc2802..5728ea4620 100644 --- a/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml +++ b/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml @@ -31,8 +31,6 @@ transport_unixpipe = [] async-trait = { workspace = true } tracing = {workspace = true} rand = { workspace = true, features = ["default"] } -zenoh-buffers = { workspace = true } -zenoh-collections = { workspace = true } zenoh-core = { workspace = true } zenoh-config = { workspace = true } zenoh-link-commons = { workspace = true } diff --git a/io/zenoh-links/zenoh-link-unixsock_stream/Cargo.toml b/io/zenoh-links/zenoh-link-unixsock_stream/Cargo.toml index b915767a19..d0bd9ed322 100644 --- a/io/zenoh-links/zenoh-link-unixsock_stream/Cargo.toml +++ b/io/zenoh-links/zenoh-link-unixsock_stream/Cargo.toml @@ -33,7 +33,6 @@ description = "Internal crate for zenoh." [dependencies] async-trait = { workspace = true } -futures = { workspace = true } tracing = {workspace = true} nix = { workspace = true } tokio = { workspace = true, features = ["io-std", "macros", "net", "rt-multi-thread", "time"] } @@ -44,4 +43,3 @@ zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } zenoh-runtime = { workspace = true } -zenoh-sync = { workspace = true } diff --git a/io/zenoh-links/zenoh-link-vsock/Cargo.toml b/io/zenoh-links/zenoh-link-vsock/Cargo.toml index 4bf709b8c2..7ab05fb0e0 100644 --- a/io/zenoh-links/zenoh-link-vsock/Cargo.toml +++ b/io/zenoh-links/zenoh-link-vsock/Cargo.toml @@ -34,8 +34,6 @@ zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } -zenoh-sync = { workspace = true } -zenoh-util = { workspace = true } zenoh-runtime = { workspace = true } # Workspaces does not support platform dependent dependencies, and diff --git a/io/zenoh-links/zenoh-link-ws/Cargo.toml b/io/zenoh-links/zenoh-link-ws/Cargo.toml index 63d78a5cb5..290dc36e33 100644 --- a/io/zenoh-links/zenoh-link-ws/Cargo.toml +++ b/io/zenoh-links/zenoh-link-ws/Cargo.toml @@ -43,6 +43,5 @@ zenoh-core = { workspace = true } zenoh-link-commons = { workspace = true } zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } -zenoh-sync = { workspace = true } zenoh-util = { workspace = true } zenoh-runtime = { workspace = true } diff --git a/io/zenoh-transport/Cargo.toml b/io/zenoh-transport/Cargo.toml index a3dabbae0e..2fd74c8b0b 100644 --- a/io/zenoh-transport/Cargo.toml +++ b/io/zenoh-transport/Cargo.toml @@ -75,7 +75,6 @@ sha3 = { workspace = true } serde = { workspace = true, features = ["default"] } zenoh-buffers = { workspace = true } zenoh-codec = { workspace = true } -zenoh-collections = { workspace = true } zenoh-config = { workspace = true } zenoh-core = { workspace = true } zenoh-crypto = { workspace = true } diff --git a/plugins/zenoh-backend-example/Cargo.toml b/plugins/zenoh-backend-example/Cargo.toml index 9f548e1187..9ff3235128 100644 --- a/plugins/zenoh-backend-example/Cargo.toml +++ b/plugins/zenoh-backend-example/Cargo.toml @@ -29,13 +29,13 @@ name = "zenoh_backend_example" crate-type = ["cdylib"] [dependencies] -const_format = { workspace = true } -futures = { workspace = true } git-version = { workspace = true } -tracing = { workspace = true } tokio = { workspace = true } serde_json = { workspace = true } zenoh = { workspace = true, features = ["default"] } zenoh-plugin-trait = { workspace = true } async-trait = { workspace = true } zenoh_backend_traits = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["git-version"] \ No newline at end of file diff --git a/plugins/zenoh-plugin-example/Cargo.toml b/plugins/zenoh-plugin-example/Cargo.toml index 5341adcf8c..61f9d859c7 100644 --- a/plugins/zenoh-plugin-example/Cargo.toml +++ b/plugins/zenoh-plugin-example/Cargo.toml @@ -34,7 +34,6 @@ name = "zenoh_plugin_example" crate-type = ["cdylib"] [dependencies] -const_format = { workspace = true } zenoh-util = { workspace = true } futures = { workspace = true } lazy_static = { workspace = true } @@ -49,3 +48,6 @@ zenoh = { workspace = true, features = [ "unstable", ] } zenoh-plugin-trait = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["git-version"] \ No newline at end of file diff --git a/plugins/zenoh-plugin-rest/Cargo.toml b/plugins/zenoh-plugin-rest/Cargo.toml index ba35c43c86..ce1385034a 100644 --- a/plugins/zenoh-plugin-rest/Cargo.toml +++ b/plugins/zenoh-plugin-rest/Cargo.toml @@ -34,7 +34,6 @@ crate-type = ["cdylib", "rlib"] [dependencies] anyhow = { workspace = true, features = ["default"] } base64 = { workspace = true } -const_format = { workspace = true } flume = { workspace = true } futures = { workspace = true } git-version = { workspace = true } diff --git a/plugins/zenoh-plugin-storage-manager/Cargo.toml b/plugins/zenoh-plugin-storage-manager/Cargo.toml index 27458af929..012bfb7a9f 100644 --- a/plugins/zenoh-plugin-storage-manager/Cargo.toml +++ b/plugins/zenoh-plugin-storage-manager/Cargo.toml @@ -34,18 +34,15 @@ crate-type = ["cdylib", "rlib"] [dependencies] async-trait = { workspace = true } crc = { workspace = true } -const_format = { workspace = true } derive-new = { workspace = true } flume = { workspace = true } futures = { workspace = true } git-version = { workspace = true } lazy_static = { workspace = true } -libloading = { workspace = true } tracing = { workspace = true } serde = { workspace = true, features = ["default"] } serde_json = { workspace = true } tokio = { workspace = true } -urlencoding = { workspace = true } zenoh = { workspace = true, features = [ "default", "plugins", @@ -54,7 +51,6 @@ zenoh = { workspace = true, features = [ ] } zenoh-plugin-trait = { workspace = true } zenoh_backend_traits = { workspace = true } -zenoh-util = { workspace = true } [build-dependencies] rustc_version = { workspace = true } @@ -74,3 +70,6 @@ copyright = "2024 ZettaScale Technology" section = "net" license-file = ["../../LICENSE", "0"] depends = "zenohd (=1.0.0~dev-1)" + +[package.metadata.cargo-machete] +ignored = ["git-version"] \ No newline at end of file diff --git a/plugins/zenoh-plugin-trait/Cargo.toml b/plugins/zenoh-plugin-trait/Cargo.toml index 8a355f6e47..77d018210c 100644 --- a/plugins/zenoh-plugin-trait/Cargo.toml +++ b/plugins/zenoh-plugin-trait/Cargo.toml @@ -30,8 +30,8 @@ name = "zenoh_plugin_trait" libloading = { workspace = true } tracing = { workspace = true } serde = { workspace = true } -serde_json = { workspace = true } +git-version = { workspace = true } zenoh-macros = { workspace = true } zenoh-result = { workspace = true } zenoh-util = { workspace = true } -zenoh-keyexpr = { workspace = true, features = ["internal", "unstable"] } \ No newline at end of file +zenoh-keyexpr = { workspace = true, features = ["internal", "unstable"] } diff --git a/zenoh-ext/Cargo.toml b/zenoh-ext/Cargo.toml index 4f2613cb70..63516bb253 100644 --- a/zenoh-ext/Cargo.toml +++ b/zenoh-ext/Cargo.toml @@ -43,11 +43,8 @@ bincode = { workspace = true } zenoh-util = { workspace = true } flume = { workspace = true } futures = { workspace = true } -phf = { workspace = true } tracing = { workspace = true } serde = { workspace = true, features = ["default"] } -serde_cbor = { workspace = true } -serde_json = { workspace = true } zenoh = { workspace = true, features = ["unstable", "internal"], default-features = false } zenoh-macros = { workspace = true } diff --git a/zenoh-ext/examples/Cargo.toml b/zenoh-ext/examples/Cargo.toml index 9cca8848ff..8dae03e596 100644 --- a/zenoh-ext/examples/Cargo.toml +++ b/zenoh-ext/examples/Cargo.toml @@ -33,15 +33,12 @@ default = [] [dependencies] tokio = { workspace = true, features = ["rt", "sync", "time", "macros", "io-std"] } -bincode = { workspace = true } -zenoh-util = {workspace = true } -flume = { workspace = true } futures = { workspace = true } -tracing = {workspace = true} -serde = { workspace = true, features = ["default"] } zenoh = { workspace = true, features = ["unstable"], default-features = false } -zenoh-ext = {workspace = true } clap = { workspace = true, features = ["derive"] } +zenoh-ext = { workspace = true } + +[dev-dependencies] [[example]] name = "z_query_sub" diff --git a/zenoh/Cargo.toml b/zenoh/Cargo.toml index 7bdb393a6c..701c22039a 100644 --- a/zenoh/Cargo.toml +++ b/zenoh/Cargo.toml @@ -70,11 +70,8 @@ tokio = { workspace = true, features = ["rt", "macros", "time"] } tokio-util = { workspace = true } ahash = { workspace = true } async-trait = { workspace = true } -base64 = { workspace = true } bytes = { workspace = true } -event-listener = { workspace = true } flume = { workspace = true } -form_urlencoded = { workspace = true } futures = { workspace = true } git-version = { workspace = true } itertools = { workspace = true } @@ -85,24 +82,20 @@ paste = { workspace = true } petgraph = { workspace = true } phf = { workspace = true } rand = { workspace = true, features = ["default"] } -regex = { workspace = true } serde = { workspace = true, features = ["default"] } serde_cbor = { workspace = true } serde_json = { workspace = true } serde-pickle = { workspace = true } serde_yaml = { workspace = true } socket2 = { workspace = true } -stop-token = { workspace = true } uhlc = { workspace = true, features = ["default"] } unwrap-infallible = { workspace = true } -uuid = { workspace = true, features = ["default"] } vec_map = { workspace = true } zenoh-buffers = { workspace = true, features = ["std"] } zenoh-codec = { workspace = true } zenoh-collections = { workspace = true, features = ["std"] } zenoh-config = { workspace = true } zenoh-core = { workspace = true } -zenoh-crypto = { workspace = true } zenoh-keyexpr = { workspace = true } zenoh-link = { workspace = true } zenoh-macros = { workspace = true } From 3136ef66944623f2d0c543d2bec29edfd4f55be9 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 5 Sep 2024 15:12:09 +0200 Subject: [PATCH 08/17] Encapsulate ZBufSliceIterator in ZBytesSliceIterator --- zenoh/src/api/bytes.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index 9595a70d23..269451388d 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -345,8 +345,8 @@ impl ZBytes { /// assert_eq!(buf1.as_slice(), iter.next().unwrap()); /// assert_eq!(buf2.as_slice(), iter.next().unwrap()); /// ``` - pub fn slices(&self) -> impl Iterator { - self.0.slices() + pub fn slices(&self) -> ZBytesSliceIterator<'_> { + ZBytesSliceIterator(self.0.slices()) } /// Serialize an object of type `T` as a [`ZBytes`] using the [`ZSerde`]. @@ -649,6 +649,22 @@ impl std::io::Write for ZBytesWriter<'_> { } } +/// An iterator that implements [`std::iter::Iterator`] trait to iterate on [`&[u8]`]. +#[repr(transparent)] +pub struct ZBytesSliceIterator<'a>(ZBytesSliceIteratorInner<'a>); + +// Typedef to make clippy happy about complex type. Encapsulate inner `ZBufSliceOperator`. +type ZBytesSliceIteratorInner<'a> = + std::iter::Map, fn(&'a ZSlice) -> &'a [u8]>; + +impl<'a> Iterator for ZBytesSliceIterator<'a> { + type Item = &'a [u8]; + + fn next(&mut self) -> Option { + self.0.next() + } +} + /// An iterator that implements [`std::iter::Iterator`] trait to iterate on values `T` in a [`ZBytes`]. /// Note that [`ZBytes`] contains a serialized version of `T` and iterating over a [`ZBytes`] performs lazy deserialization. #[repr(transparent)] From 6bc81bb5a5b35d8010c2d27afdc738af9de1f02c Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 5 Sep 2024 15:19:20 +0200 Subject: [PATCH 09/17] Update ZBytes comment --- zenoh/src/api/bytes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index 269451388d..c79e07a328 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -86,7 +86,7 @@ impl From for Option { } } -/// Trait to encode a type `T` into a [`Value`]. +/// Trait to encode a type `T` into a [`ZBytes`]. pub trait Serialize { type Output; From 1d3be7e9766f2dd069935797b6252d94830d6d9d Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Thu, 5 Sep 2024 15:27:39 +0200 Subject: [PATCH 10/17] #[derive(Debug)] for ZBytesSliceIterator --- zenoh/src/api/bytes.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index c79e07a328..d8004bbcf0 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -651,6 +651,7 @@ impl std::io::Write for ZBytesWriter<'_> { /// An iterator that implements [`std::iter::Iterator`] trait to iterate on [`&[u8]`]. #[repr(transparent)] +#[derive(Debug)] pub struct ZBytesSliceIterator<'a>(ZBytesSliceIteratorInner<'a>); // Typedef to make clippy happy about complex type. Encapsulate inner `ZBufSliceOperator`. From 3ef3b9ae37cce21196fe2f0f0ba0a524ee17617a Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Thu, 5 Sep 2024 16:34:21 +0200 Subject: [PATCH 11/17] expose ZBytesSliceIterator to public api --- zenoh/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 0190acc319..12adb11678 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -222,7 +222,7 @@ pub mod bytes { builders::sample::EncodingBuilderTrait, bytes::{ Deserialize, OptionZBytes, Serialize, ZBytes, ZBytesIterator, ZBytesReader, - ZBytesWriter, ZDeserializeError, ZSerde, + ZBytesSliceIterator, ZBytesWriter, ZDeserializeError, ZSerde, }, encoding::Encoding, }; From ea41e06a301f73ab60724a751f8ab3c354df98ee Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 6 Sep 2024 07:43:59 +0000 Subject: [PATCH 12/17] Apply lints from Clippy 1.81.0 --- io/zenoh-links/zenoh-link-tcp/src/unicast.rs | 2 +- io/zenoh-links/zenoh-link-vsock/src/unicast.rs | 2 +- io/zenoh-transport/src/unicast/establishment/accept.rs | 9 ++------- io/zenoh-transport/src/unicast/establishment/open.rs | 9 ++------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs index 7532055f8e..ec2e6e06b7 100644 --- a/io/zenoh-links/zenoh-link-tcp/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-tcp/src/unicast.rs @@ -348,7 +348,7 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastTcp { // Update the endpoint locator address endpoint = EndPoint::new( endpoint.protocol(), - &format!("{local_addr}"), + format!("{local_addr}"), endpoint.metadata(), endpoint.config(), )?; diff --git a/io/zenoh-links/zenoh-link-vsock/src/unicast.rs b/io/zenoh-links/zenoh-link-vsock/src/unicast.rs index e7b261f292..979048b585 100644 --- a/io/zenoh-links/zenoh-link-vsock/src/unicast.rs +++ b/io/zenoh-links/zenoh-link-vsock/src/unicast.rs @@ -267,7 +267,7 @@ impl LinkManagerUnicastTrait for LinkManagerUnicastVsock { // Update the endpoint locator address endpoint = EndPoint::new( endpoint.protocol(), - &format!("{local_addr}"), + format!("{local_addr}"), endpoint.metadata(), endpoint.config(), )?; diff --git a/io/zenoh-transport/src/unicast/establishment/accept.rs b/io/zenoh-transport/src/unicast/establishment/accept.rs index 64949357c6..01d38a47b8 100644 --- a/io/zenoh-transport/src/unicast/establishment/accept.rs +++ b/io/zenoh-transport/src/unicast/establishment/accept.rs @@ -24,7 +24,6 @@ use zenoh_link::LinkUnicast; use zenoh_protocol::{ core::{Field, Resolution, WhatAmI, ZenohIdProto}, transport::{ - batch_size, close::{self, Close}, BatchSize, InitAck, OpenAck, TransportBody, TransportMessage, TransportSn, }, @@ -211,11 +210,7 @@ impl<'a, 'b: 'a> AcceptFsm for &'a mut AcceptLink<'b> { }; // Compute the minimum batch size - state.transport.batch_size = state - .transport - .batch_size - .min(init_syn.batch_size) - .min(batch_size::UNICAST); + state.transport.batch_size = state.transport.batch_size.min(init_syn.batch_size); // Extension QoS self.ext_qos @@ -687,7 +682,7 @@ pub(crate) async fn accept_link(link: LinkUnicast, manager: &TransportManager) - let iack_out = { let mut state = State { transport: StateTransport { - batch_size: manager.config.batch_size.min(batch_size::UNICAST).min(mtu), + batch_size: manager.config.batch_size.min(mtu), resolution: manager.config.resolution, ext_qos: ext::qos::StateAccept::new(manager.config.unicast.is_qos), #[cfg(feature = "transport_multilink")] diff --git a/io/zenoh-transport/src/unicast/establishment/open.rs b/io/zenoh-transport/src/unicast/establishment/open.rs index a9e797228e..468b2095d9 100644 --- a/io/zenoh-transport/src/unicast/establishment/open.rs +++ b/io/zenoh-transport/src/unicast/establishment/open.rs @@ -22,8 +22,7 @@ use zenoh_link::LinkUnicast; use zenoh_protocol::{ core::{Field, Resolution, WhatAmI, ZenohIdProto}, transport::{ - batch_size, close, BatchSize, Close, InitSyn, OpenSyn, TransportBody, TransportMessage, - TransportSn, + close, BatchSize, Close, InitSyn, OpenSyn, TransportBody, TransportMessage, TransportSn, }, }; use zenoh_result::ZResult; @@ -571,11 +570,7 @@ pub(crate) async fn open_link( let mut state = State { transport: StateTransport { - batch_size: manager - .config - .batch_size - .min(batch_size::UNICAST) - .min(link.config.batch.mtu), + batch_size: manager.config.batch_size.min(link.config.batch.mtu), resolution: manager.config.resolution, ext_qos: ext::qos::StateOpen::new(manager.config.unicast.is_qos), #[cfg(feature = "transport_multilink")] From c224401814309383b39e8ee521c08992b97e3d50 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 6 Sep 2024 08:29:12 +0000 Subject: [PATCH 13/17] Silence `clippy::unnecessary_min_or_max` --- .../src/unicast/establishment/accept.rs | 15 +++++++++++++-- .../src/unicast/establishment/open.rs | 12 ++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/io/zenoh-transport/src/unicast/establishment/accept.rs b/io/zenoh-transport/src/unicast/establishment/accept.rs index 01d38a47b8..995b07230e 100644 --- a/io/zenoh-transport/src/unicast/establishment/accept.rs +++ b/io/zenoh-transport/src/unicast/establishment/accept.rs @@ -24,6 +24,7 @@ use zenoh_link::LinkUnicast; use zenoh_protocol::{ core::{Field, Resolution, WhatAmI, ZenohIdProto}, transport::{ + batch_size, close::{self, Close}, BatchSize, InitAck, OpenAck, TransportBody, TransportMessage, TransportSn, }, @@ -210,7 +211,14 @@ impl<'a, 'b: 'a> AcceptFsm for &'a mut AcceptLink<'b> { }; // Compute the minimum batch size - state.transport.batch_size = state.transport.batch_size.min(init_syn.batch_size); + #[allow(clippy::unnecessary_min_or_max)] + { + state.transport.batch_size = state + .transport + .batch_size + .min(init_syn.batch_size) + .min(batch_size::UNICAST); + } // Extension QoS self.ext_qos @@ -679,10 +687,13 @@ pub(crate) async fn accept_link(link: LinkUnicast, manager: &TransportManager) - }; } + #[allow(clippy::unnecessary_min_or_max)] + let batch_size = manager.config.batch_size.min(batch_size::UNICAST).min(mtu); + let iack_out = { let mut state = State { transport: StateTransport { - batch_size: manager.config.batch_size.min(mtu), + batch_size, resolution: manager.config.resolution, ext_qos: ext::qos::StateAccept::new(manager.config.unicast.is_qos), #[cfg(feature = "transport_multilink")] diff --git a/io/zenoh-transport/src/unicast/establishment/open.rs b/io/zenoh-transport/src/unicast/establishment/open.rs index 468b2095d9..88e139b23d 100644 --- a/io/zenoh-transport/src/unicast/establishment/open.rs +++ b/io/zenoh-transport/src/unicast/establishment/open.rs @@ -22,7 +22,8 @@ use zenoh_link::LinkUnicast; use zenoh_protocol::{ core::{Field, Resolution, WhatAmI, ZenohIdProto}, transport::{ - close, BatchSize, Close, InitSyn, OpenSyn, TransportBody, TransportMessage, TransportSn, + batch_size, close, BatchSize, Close, InitSyn, OpenSyn, TransportBody, TransportMessage, + TransportSn, }, }; use zenoh_result::ZResult; @@ -568,9 +569,16 @@ pub(crate) async fn open_link( ext_compression: ext::compression::CompressionFsm::new(), }; + #[allow(clippy::unnecessary_min_or_max)] + let batch_size = manager + .config + .batch_size + .min(link.config.batch.mtu) + .min(batch_size::UNICAST); + let mut state = State { transport: StateTransport { - batch_size: manager.config.batch_size.min(link.config.batch.mtu), + batch_size, resolution: manager.config.resolution, ext_qos: ext::qos::StateOpen::new(manager.config.unicast.is_qos), #[cfg(feature = "transport_multilink")] From c51f62910464bcf41e356366df688a9fa8a92e9b Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 6 Sep 2024 11:39:17 +0200 Subject: [PATCH 14/17] Comment `#[allow(clippy::unnecessary_min_or_max)]` Co-authored-by: Luca Cominardi --- io/zenoh-transport/src/unicast/establishment/accept.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io/zenoh-transport/src/unicast/establishment/accept.rs b/io/zenoh-transport/src/unicast/establishment/accept.rs index 995b07230e..28cd6e757b 100644 --- a/io/zenoh-transport/src/unicast/establishment/accept.rs +++ b/io/zenoh-transport/src/unicast/establishment/accept.rs @@ -687,6 +687,8 @@ pub(crate) async fn accept_link(link: LinkUnicast, manager: &TransportManager) - }; } + // Clippy raises a warning because `batch_size::UNICAST` is currently equal to `BatchSize::MAX`. + // However, the current code catches the cases where `batch_size::UNICAST` is different from `BatchSize::MAX`. #[allow(clippy::unnecessary_min_or_max)] let batch_size = manager.config.batch_size.min(batch_size::UNICAST).min(mtu); From 165ec0d15ccad849cc038dd725d5b0de787e22a8 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 6 Sep 2024 11:39:25 +0200 Subject: [PATCH 15/17] Comment `#[allow(clippy::unnecessary_min_or_max)]` Co-authored-by: Luca Cominardi --- io/zenoh-transport/src/unicast/establishment/accept.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io/zenoh-transport/src/unicast/establishment/accept.rs b/io/zenoh-transport/src/unicast/establishment/accept.rs index 28cd6e757b..9d34896d95 100644 --- a/io/zenoh-transport/src/unicast/establishment/accept.rs +++ b/io/zenoh-transport/src/unicast/establishment/accept.rs @@ -211,6 +211,8 @@ impl<'a, 'b: 'a> AcceptFsm for &'a mut AcceptLink<'b> { }; // Compute the minimum batch size + // Clippy raises a warning because `batch_size::UNICAST` is currently equal to `BatchSize::MAX`. + // However, the current code catches the cases where `batch_size::UNICAST` is different from `BatchSize::MAX`. #[allow(clippy::unnecessary_min_or_max)] { state.transport.batch_size = state From cc6cc84bbf47ae31b913044cfe81b18ea0c24500 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 6 Sep 2024 11:39:35 +0200 Subject: [PATCH 16/17] Comment `#[allow(clippy::unnecessary_min_or_max)]` Co-authored-by: Luca Cominardi --- io/zenoh-transport/src/unicast/establishment/open.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io/zenoh-transport/src/unicast/establishment/open.rs b/io/zenoh-transport/src/unicast/establishment/open.rs index 88e139b23d..b8346d49a6 100644 --- a/io/zenoh-transport/src/unicast/establishment/open.rs +++ b/io/zenoh-transport/src/unicast/establishment/open.rs @@ -569,6 +569,8 @@ pub(crate) async fn open_link( ext_compression: ext::compression::CompressionFsm::new(), }; + // Clippy raises a warning because `batch_size::UNICAST` is currently equal to `BatchSize::MAX`. + // However, the current code catches the cases where `batch_size::UNICAST` is different from `BatchSize::MAX`. #[allow(clippy::unnecessary_min_or_max)] let batch_size = manager .config From f2f4fc9d5507051e4cb74885c992a793352fbf45 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 6 Sep 2024 09:10:33 +0000 Subject: [PATCH 17/17] Fix formatting --- io/zenoh-transport/src/unicast/establishment/open.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io/zenoh-transport/src/unicast/establishment/open.rs b/io/zenoh-transport/src/unicast/establishment/open.rs index b8346d49a6..ff73e213c2 100644 --- a/io/zenoh-transport/src/unicast/establishment/open.rs +++ b/io/zenoh-transport/src/unicast/establishment/open.rs @@ -569,7 +569,7 @@ pub(crate) async fn open_link( ext_compression: ext::compression::CompressionFsm::new(), }; - // Clippy raises a warning because `batch_size::UNICAST` is currently equal to `BatchSize::MAX`. + // Clippy raises a warning because `batch_size::UNICAST` is currently equal to `BatchSize::MAX`. // However, the current code catches the cases where `batch_size::UNICAST` is different from `BatchSize::MAX`. #[allow(clippy::unnecessary_min_or_max)] let batch_size = manager