Trait rustc_serialize::serialize::Encoder
source · pub trait Encoder {
Show 20 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_i8(&mut self, v: i8);
fn emit_bool(&mut self, v: bool);
fn emit_f64(&mut self, v: f64);
fn emit_f32(&mut self, v: f32);
fn emit_char(&mut self, v: char);
fn emit_str(&mut self, v: &str);
fn emit_raw_bytes(&mut self, s: &[u8]);
fn emit_enum_variant<F>(&mut self, v_id: usize, f: F)
where
F: FnOnce(&mut Self),
{ ... }
fn emit_fieldless_enum_variant<const ID: usize>(&mut self) { ... }
}
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.
Required Methods
source
fn emit_usize(&mut self, v: usize)
source
fn emit_isize(&mut self, v: isize)
source
fn emit_raw_bytes(&mut self, s: &[u8])
Provided Methods
sourcefn emit_enum_variant<F>(&mut self, v_id: usize, f: F)where
fn emit_enum_variant<F>(&mut self, v_id: usize, f: F)where
F: FnOnce(&mut Self),
source