diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe42f4b1..b18ea148e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Implemented (de)ser for `core::ops::range` + ## [0.10.0] - 2023-01-19 - Fix no-std feature (some of the imports incorrectly used `std::` instead of `crate::maybestd::`) diff --git a/borsh-derive-internal/src/lib.rs b/borsh-derive-internal/src/lib.rs index e01b99c85..01ef40749 100644 --- a/borsh-derive-internal/src/lib.rs +++ b/borsh-derive-internal/src/lib.rs @@ -1,4 +1,6 @@ #![recursion_limit = "128"] +// TODO: re-enable this lint when we bump msrv to 1.58 +#![allow(clippy::uninlined_format_args)] mod attribute_helpers; mod enum_de; diff --git a/borsh-derive/src/lib.rs b/borsh-derive/src/lib.rs index 55f368b86..86ae04d58 100644 --- a/borsh-derive/src/lib.rs +++ b/borsh-derive/src/lib.rs @@ -1,3 +1,5 @@ +// TODO: re-enable this lint when we bump msrv to 1.58 +#![allow(clippy::uninlined_format_args)] extern crate proc_macro; use proc_macro::TokenStream; use proc_macro2::Span; diff --git a/borsh-schema-derive-internal/src/lib.rs b/borsh-schema-derive-internal/src/lib.rs index b75c1ee6a..23c1bb89a 100644 --- a/borsh-schema-derive-internal/src/lib.rs +++ b/borsh-schema-derive-internal/src/lib.rs @@ -1,4 +1,6 @@ #![recursion_limit = "128"] +// TODO: re-enable this lint when we bump msrv to 1.58 +#![allow(clippy::uninlined_format_args)] mod helpers; diff --git a/borsh/src/de/mod.rs b/borsh/src/de/mod.rs index 973af3f79..c90d030b3 100644 --- a/borsh/src/de/mod.rs +++ b/borsh/src/de/mod.rs @@ -281,6 +281,19 @@ impl BorshDeserialize for bool { } } +impl BorshDeserialize for core::ops::Range +where + T: BorshDeserialize, +{ + #[inline] + fn deserialize_reader(reader: &mut R) -> Result { + Ok(Self { + start: T::deserialize_reader(reader)?, + end: T::deserialize_reader(reader)?, + }) + } +} + impl BorshDeserialize for Option where T: BorshDeserialize, diff --git a/borsh/src/generate_schema_schema.rs b/borsh/src/generate_schema_schema.rs index f93bdb327..ed0fcac92 100644 --- a/borsh/src/generate_schema_schema.rs +++ b/borsh/src/generate_schema_schema.rs @@ -1,4 +1,6 @@ //! Generate `BorshSchemaCointainer` for `BorshSchemaContainer` and save it into a file. +// TODO: re-enable this lint when we bump msrv to 1.58 +#![allow(clippy::uninlined_format_args)] use borsh::schema::BorshSchema; use borsh::BorshSerialize; use std::fs::File; diff --git a/borsh/src/lib.rs b/borsh/src/lib.rs index 8db27c42e..cf51b18a1 100644 --- a/borsh/src/lib.rs +++ b/borsh/src/lib.rs @@ -1,4 +1,6 @@ #![cfg_attr(not(feature = "std"), no_std)] +// TODO: re-enable this lint when we bump msrv to 1.58 +#![allow(clippy::uninlined_format_args)] #[cfg(not(feature = "std"))] extern crate alloc; diff --git a/borsh/src/ser/mod.rs b/borsh/src/ser/mod.rs index 84e0573aa..b905db07a 100644 --- a/borsh/src/ser/mod.rs +++ b/borsh/src/ser/mod.rs @@ -157,6 +157,17 @@ impl BorshSerialize for bool { } } +impl BorshSerialize for core::ops::Range +where + T: BorshSerialize, +{ + #[inline] + fn serialize(&self, writer: &mut W) -> Result<()> { + self.start.serialize(writer)?; + self.end.serialize(writer) + } +} + impl BorshSerialize for Option where T: BorshSerialize, diff --git a/borsh/tests/test_simple_structs.rs b/borsh/tests/test_simple_structs.rs index deb749850..ce484828b 100644 --- a/borsh/tests/test_simple_structs.rs +++ b/borsh/tests/test_simple_structs.rs @@ -23,6 +23,7 @@ struct A<'a> { lazy: Option, c: std::borrow::Cow<'a, str>, cow_arr: std::borrow::Cow<'a, [std::borrow::Cow<'a, str>]>, + range_u32: std::ops::Range, #[borsh_skip] skipped: Option, } @@ -105,6 +106,7 @@ fn test_simple_struct() { lazy: Some(5), c: std::borrow::Cow::Borrowed("Hello"), cow_arr: std::borrow::Cow::Borrowed(&cow_arr), + range_u32: 12..71, skipped: Some(6), }; let encoded_a = a.try_to_vec().unwrap(); @@ -140,6 +142,7 @@ fn test_simple_struct() { std::borrow::Cow::Borrowed("Hello1"), std::borrow::Cow::Owned("Hello2".to_string()), ]), + range_u32: 12..71, skipped: None, };