diff --git a/fe2o3-amqp-management/src/lib.rs b/fe2o3-amqp-management/src/lib.rs index 32b0c877..43a14ef3 100644 --- a/fe2o3-amqp-management/src/lib.rs +++ b/fe2o3-amqp-management/src/lib.rs @@ -1,4 +1,5 @@ #![deny(missing_docs, missing_debug_implementations)] +#![allow(clippy::result_large_err)] // TODO: refactor in 0.14.0 //! An experimental implementation of AMQP 1.0 management working draft with `fe2o3-amqp` //! @@ -25,12 +26,3 @@ pub const DEFAULT_CLIENT_NODE_ADDRESS: &str = "mgmt-client"; pub use client::MgmtClient; pub use request::Request; pub use response::Response; - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} diff --git a/fe2o3-amqp-ws/src/native.rs b/fe2o3-amqp-ws/src/native.rs index d64110db..f52718a0 100644 --- a/fe2o3-amqp-ws/src/native.rs +++ b/fe2o3-amqp-ws/src/native.rs @@ -301,6 +301,7 @@ fn map_amqp_websocket_request(req: impl IntoClientRequest) -> Result Result { use http::StatusCode; diff --git a/fe2o3-amqp/src/lib.rs b/fe2o3-amqp/src/lib.rs index f4d5649c..f0df00b8 100644 --- a/fe2o3-amqp/src/lib.rs +++ b/fe2o3-amqp/src/lib.rs @@ -1,6 +1,7 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(missing_docs, missing_debug_implementations)] #![warn(clippy::unused_async)] +#![allow(clippy::result_large_err)] // TODO: refactor in 0.14.0 //! A rust implementation of AMQP 1.0 protocol based on serde and tokio. //! diff --git a/serde_amqp/Cargo.toml b/serde_amqp/Cargo.toml index b9a65f09..e2637c30 100644 --- a/serde_amqp/Cargo.toml +++ b/serde_amqp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_amqp" -version = "0.13.0" +version = "0.13.1" edition = "2021" description = "A serde implementation of AMQP1.0 protocol." license = "MIT/Apache-2.0" diff --git a/serde_amqp/Changelog.md b/serde_amqp/Changelog.md index 67669609..cdbbcb4c 100644 --- a/serde_amqp/Changelog.md +++ b/serde_amqp/Changelog.md @@ -1,5 +1,9 @@ # Change Log +## 0.13.1 + +1. Added `to_lazy_value` + ## 0.13.0 ### Breaking diff --git a/serde_amqp/src/lazy.rs b/serde_amqp/src/lazy.rs index 972be236..4e6e14e1 100644 --- a/serde_amqp/src/lazy.rs +++ b/serde_amqp/src/lazy.rs @@ -9,6 +9,15 @@ use crate::{ __constants::LAZY_VALUE, }; +/// Serialize a value into a [`LazyValue`]. +pub fn to_lazy_value(value: &T) -> Result +where + T: Serialize, +{ + let bytes = crate::to_vec(value)?; + Ok(LazyValue(Bytes::from(bytes))) +} + /// A lazy value. /// /// This is a thin wrapper around a [`Bytes`] value that can be accessed via diff --git a/serde_amqp/src/size_ser.rs b/serde_amqp/src/size_ser.rs index 152296cc..5a32bf7d 100644 --- a/serde_amqp/src/size_ser.rs +++ b/serde_amqp/src/size_ser.rs @@ -871,6 +871,7 @@ mod tests { use serde_bytes::ByteBuf; use crate::{ + lazy::to_lazy_value, primitives::{Array, Dec128, Dec32, Dec64, Symbol, Timestamp, Uuid}, to_vec, }; @@ -1311,4 +1312,26 @@ mod tests { let size_result = serialized_size(&value); assert!(size_result.is_ok()); } + + #[test] + fn serialized_size_of_lazy_value_match_with_value() { + use crate::{described::Described, descriptor::Descriptor, primitives::*, Value}; + + let timestamp = Timestamp::from_milliseconds(12345); + let mut list = List::new(); + list.push(Value::Timestamp(timestamp)); + + let described = Described { + descriptor: Descriptor::Code(0x73), + value: Value::List(list), + }; + + let value = Value::Described(Box::new(described)); + let lazy_value = to_lazy_value(&value).unwrap(); + + let value_size = serialized_size(&value).unwrap(); + let lazy_value_size = serialized_size(&lazy_value).unwrap(); + + assert_eq!(value_size, lazy_value_size); + } }