cl-ast: more generic impls for weight_of

TODO: get rid of weight_of
This commit is contained in:
John 2025-05-05 04:19:23 -04:00
parent 883387aaf1
commit f5f905cd70

View File

@ -567,13 +567,19 @@ impl<T: WeightOf> WeightOf for Option<T> {
impl<T: WeightOf> WeightOf for [T] { impl<T: WeightOf> WeightOf for [T] {
fn weight_of(&self) -> usize { fn weight_of(&self) -> usize {
self.iter().map(|t| t.weight_of()).sum() self.iter().map(WeightOf::weight_of).sum()
}
}
impl<T: WeightOf> WeightOf for Vec<T> {
fn weight_of(&self) -> usize {
size_of::<Self>() + self.iter().map(WeightOf::weight_of).sum::<usize>()
} }
} }
impl<T: WeightOf> WeightOf for Box<T> { impl<T: WeightOf> WeightOf for Box<T> {
fn weight_of(&self) -> usize { fn weight_of(&self) -> usize {
(**self).weight_of() (**self).weight_of() + size_of::<Self>()
} }
} }