miden_protobuf/decode/
build.rs1use alloc::collections::BTreeMap;
2use alloc::vec::Vec;
3use core::fmt::Debug;
4
5use super::{MapField, OptionalField, RepeatedField};
6use crate::{BuildUnchecked, ConversionError};
7
8impl<S: BuildUnchecked> BuildUnchecked for OptionalField<S> {
10 type Output = Option<S::Output>;
11 type Error = ConversionError;
12
13 fn build_unchecked(self) -> Result<Self::Output, Self::Error> {
14 self.try_map(BuildUnchecked::build_unchecked)
15 }
16}
17
18impl<S: BuildUnchecked> BuildUnchecked for RepeatedField<S> {
21 type Output = Vec<S::Output>;
22 type Error = ConversionError;
23
24 fn build_unchecked(self) -> Result<Self::Output, Self::Error> {
25 self.try_map(BuildUnchecked::build_unchecked)
26 }
27}
28
29impl<K: Ord + Debug, S: BuildUnchecked> BuildUnchecked for MapField<BTreeMap<K, S>> {
32 type Output = BTreeMap<K, S::Output>;
33 type Error = ConversionError;
34
35 fn build_unchecked(self) -> Result<Self::Output, Self::Error> {
36 self.try_map(BuildUnchecked::build_unchecked)
37 }
38}
39
40#[cfg(feature = "std")]
43impl<K: Eq + core::hash::Hash + Debug, S: BuildUnchecked> BuildUnchecked
44 for MapField<std::collections::HashMap<K, S>>
45{
46 type Output = std::collections::HashMap<K, S::Output>;
47 type Error = ConversionError;
48
49 fn build_unchecked(self) -> Result<Self::Output, Self::Error> {
50 self.try_map(BuildUnchecked::build_unchecked)
51 }
52}