musli_core/en/
entry_encoder.rs1use crate::Context;
2
3use super::{Encode, Encoder};
4
5pub trait EntryEncoder: Sized {
7 type Cx: Context<Error = Self::Error>;
9 type Error;
11 type Mode: 'static;
13 type EncodeKey<'this>: Encoder<Cx = Self::Cx, Error = Self::Error, Mode = Self::Mode>
15 where
16 Self: 'this;
17 type EncodeValue<'this>: Encoder<Cx = Self::Cx, Error = Self::Error, Mode = Self::Mode>
19 where
20 Self: 'this;
21
22 fn cx(&self) -> Self::Cx;
24
25 #[must_use = "Encoders must be consumed"]
27 fn encode_key(&mut self) -> Result<Self::EncodeKey<'_>, Self::Error>;
28
29 #[must_use = "Encoders must be consumed"]
31 fn encode_value(&mut self) -> Result<Self::EncodeValue<'_>, Self::Error>;
32
33 fn finish_entry(self) -> Result<(), Self::Error>;
35
36 #[inline]
38 fn insert_entry<K, V>(mut self, key: K, value: V) -> Result<(), Self::Error>
39 where
40 K: Encode<Self::Mode>,
41 V: Encode<Self::Mode>,
42 {
43 self.encode_key()?.encode(key)?;
44 self.encode_value()?.encode(value)?;
45 self.finish_entry()
46 }
47}