1use alloc::boxed::Box;
2
3use crate::{if_typesize_details, TypeSize};
4
5impl<T: TypeSize> TypeSize for Box<[T]> {
6 fn extra_size(&self) -> usize {
7 self.iter().map(T::get_size).sum()
8 }
9
10 #[cfg(feature = "details")]
11 fn get_collection_item_count(&self) -> Option<usize> {
12 Some(self.len())
13 }
14}
15
16impl TypeSize for Box<str> {
17 fn extra_size(&self) -> usize {
18 core::mem::size_of::<u8>() * self.len()
19 }
20
21 #[cfg(feature = "details")]
22 fn get_collection_item_count(&self) -> Option<usize> {
23 Some(self.len())
24 }
25}
26
27impl<T: TypeSize> TypeSize for Box<T> {
28 fn extra_size(&self) -> usize {
29 <T as TypeSize>::get_size(self)
30 }
31
32 if_typesize_details! {
33 fn get_collection_item_count(&self) -> Option<usize> {
34 <T as TypeSize>::get_collection_item_count(self)
35 }
36
37 fn get_size_details(&self) -> alloc::vec::Vec<crate::Field> {
38 <T as TypeSize>::get_size_details(self)
39 }
40 }
41}