Skip to content

Commit 2b4443d

Browse files
Implement MaxSize for serializable Range structs
Range, RangeInclusive, RangeFrom, RangeTo
1 parent cb14463 commit 2b4443d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

source/postcard/src/max_size.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use core::{
1414
NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
1515
NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
1616
},
17+
ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive},
1718
};
1819

1920
/// This trait is used to enforce the maximum size required to
@@ -201,6 +202,22 @@ impl<A: MaxSize, B: MaxSize, C: MaxSize, D: MaxSize, E: MaxSize, F: MaxSize> Max
201202
+ F::POSTCARD_MAX_SIZE;
202203
}
203204

205+
impl<T: MaxSize> MaxSize for Range<T> {
206+
const POSTCARD_MAX_SIZE: usize = T::POSTCARD_MAX_SIZE * 2;
207+
}
208+
209+
impl<T: MaxSize> MaxSize for RangeInclusive<T> {
210+
const POSTCARD_MAX_SIZE: usize = T::POSTCARD_MAX_SIZE * 2;
211+
}
212+
213+
impl<T: MaxSize> MaxSize for RangeFrom<T> {
214+
const POSTCARD_MAX_SIZE: usize = T::POSTCARD_MAX_SIZE;
215+
}
216+
217+
impl<T: MaxSize> MaxSize for RangeTo<T> {
218+
const POSTCARD_MAX_SIZE: usize = T::POSTCARD_MAX_SIZE;
219+
}
220+
204221
#[cfg(feature = "alloc")]
205222
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
206223
impl<T: MaxSize> MaxSize for Box<T> {

0 commit comments

Comments
 (0)