pub trait Encoder {
const DETERMINISTIC_HASH_MAP_ENCODE: bool = false;
Show 19 methods
// Required methods
fn emit_usize(&mut self, v: usize);
fn emit_u128(&mut self, v: u128);
fn emit_u64(&mut self, v: u64);
fn emit_u32(&mut self, v: u32);
fn emit_u16(&mut self, v: u16);
fn emit_u8(&mut self, v: u8);
fn emit_isize(&mut self, v: isize);
fn emit_i128(&mut self, v: i128);
fn emit_i64(&mut self, v: i64);
fn emit_i32(&mut self, v: i32);
fn emit_i16(&mut self, v: i16);
fn emit_raw_bytes(&mut self, s: &[u8]);
// Provided methods
fn emit_i8(&mut self, v: i8) { ... }
fn emit_bool(&mut self, v: bool) { ... }
fn emit_char(&mut self, v: char) { ... }
fn emit_str(&mut self, v: &str) { ... }
fn emit_byte_str(&mut self, v: &[u8]) { ... }
fn encode_hash_map<K, V, S>(&mut self, map: &HashMap<K, V, S>)
where Self: Sized,
K: Encodable<Self> + for<'a> ContextOrd<&'a Self>,
V: Encodable<Self>,
S: BuildHasher { ... }
fn encode_hash_set<K, S>(&mut self, map: &HashSet<K, S>)
where Self: Sized,
K: Encodable<Self> + for<'a> ContextOrd<&'a Self>,
S: BuildHasher { ... }
}Expand description
A note about error handling.
Encoders may be fallible, but in practice failure is rare and there are so
many nested calls that typical Rust error handling (via Result and ?)
is pervasive and has non-trivial cost. Instead, impls of this trait must
implement a delayed error handling strategy. If a failure occurs, they
should record this internally, and all subsequent encoding operations can
be processed or ignored, whichever is appropriate. Then they should provide
a finish method that finishes up encoding. If the encoder is fallible,
finish should return a Result that indicates success or failure.
This current does not support f32 nor f64, as they’re not needed in any
serialized data structures. That could be changed, but consider whether it
really makes sense to store floating-point values at all.
(If you need it, revert https://github.com/rust-lang/rust/pull/109984.)
Provided Associated Constants§
Sourceconst DETERMINISTIC_HASH_MAP_ENCODE: bool = false
const DETERMINISTIC_HASH_MAP_ENCODE: bool = false
Controls whether HashMap-s are stable sorted by their key before encoding. Some encoders
don’t need determinism, improving performance.
Required Methods§
fn emit_usize(&mut self, v: usize)
fn emit_u128(&mut self, v: u128)
fn emit_u64(&mut self, v: u64)
fn emit_u32(&mut self, v: u32)
fn emit_u16(&mut self, v: u16)
fn emit_u8(&mut self, v: u8)
fn emit_isize(&mut self, v: isize)
fn emit_i128(&mut self, v: i128)
fn emit_i64(&mut self, v: i64)
fn emit_i32(&mut self, v: i32)
fn emit_i16(&mut self, v: i16)
fn emit_raw_bytes(&mut self, s: &[u8])
Provided Methods§
fn emit_i8(&mut self, v: i8)
fn emit_bool(&mut self, v: bool)
fn emit_char(&mut self, v: char)
fn emit_str(&mut self, v: &str)
fn emit_byte_str(&mut self, v: &[u8])
fn encode_hash_map<K, V, S>(&mut self, map: &HashMap<K, V, S>)where
Self: Sized,
K: Encodable<Self> + for<'a> ContextOrd<&'a Self>,
V: Encodable<Self>,
S: BuildHasher,
fn encode_hash_set<K, S>(&mut self, map: &HashSet<K, S>)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".