Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::`)
Expand Down
2 changes: 2 additions & 0 deletions borsh-derive-internal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions borsh-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions borsh-schema-derive-internal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
13 changes: 13 additions & 0 deletions borsh/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ impl BorshDeserialize for bool {
}
}

impl<T> BorshDeserialize for core::ops::Range<T>
where
T: BorshDeserialize,
{
#[inline]
fn deserialize_reader<R: Read>(reader: &mut R) -> Result<Self> {
Ok(Self {
start: T::deserialize_reader(reader)?,
end: T::deserialize_reader(reader)?,
})
}
}

impl<T> BorshDeserialize for Option<T>
where
T: BorshDeserialize,
Expand Down
2 changes: 2 additions & 0 deletions borsh/src/generate_schema_schema.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions borsh/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
11 changes: 11 additions & 0 deletions borsh/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ impl BorshSerialize for bool {
}
}

impl<T> BorshSerialize for core::ops::Range<T>
where
T: BorshSerialize,
{
#[inline]
fn serialize<W: Write>(&self, writer: &mut W) -> Result<()> {
self.start.serialize(writer)?;
self.end.serialize(writer)
}
}

impl<T> BorshSerialize for Option<T>
where
T: BorshSerialize,
Expand Down
3 changes: 3 additions & 0 deletions borsh/tests/test_simple_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct A<'a> {
lazy: Option<u64>,
c: std::borrow::Cow<'a, str>,
cow_arr: std::borrow::Cow<'a, [std::borrow::Cow<'a, str>]>,
range_u32: std::ops::Range<u32>,
#[borsh_skip]
skipped: Option<u64>,
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
};

Expand Down