Trait ra_ap_rustc_serialize::Encoder
source · pub trait Encoder {
Show 16 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) { ... }
}
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.)