diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-06-16 16:00:25 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-06-16 16:20:32 +1000 |
| commit | bb02cc47c49ee3cc1e913c243d69ee7cb23df598 (patch) | |
| tree | 957f4eb12de558ee321f9a012c4cd1468c54b34d /compiler/rustc_serialize/src/serialize.rs | |
| parent | ca983054e19afd74d63c3ed37997f3bf30fe85d0 (diff) | |
| download | rust-bb02cc47c49ee3cc1e913c243d69ee7cb23df598.tar.gz rust-bb02cc47c49ee3cc1e913c243d69ee7cb23df598.zip | |
Move `finish` out of the `Encoder` trait.
This simplifies things, but requires making `CacheEncoder` non-generic. (This was previously merged as commit 4 in #94732 and then was reverted in #97905 because it caused a perf regression.)
Diffstat (limited to 'compiler/rustc_serialize/src/serialize.rs')
| -rw-r--r-- | compiler/rustc_serialize/src/serialize.rs | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/compiler/rustc_serialize/src/serialize.rs b/compiler/rustc_serialize/src/serialize.rs index 98bb18581f5..36585b8d77e 100644 --- a/compiler/rustc_serialize/src/serialize.rs +++ b/compiler/rustc_serialize/src/serialize.rs @@ -18,13 +18,10 @@ use std::sync::Arc; /// 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 when `finish()` is -/// called, an error result should be returned to indicate the failure. If no -/// failures occurred, then `finish()` should return a success result. +/// 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. pub trait Encoder { - type Ok; - type Err; - // Primitive types: fn emit_usize(&mut self, v: usize); fn emit_u128(&mut self, v: u128); @@ -64,9 +61,6 @@ pub trait Encoder { fn emit_fieldless_enum_variant<const ID: usize>(&mut self) { self.emit_usize(ID) } - - // Consume the encoder, getting the result. - fn finish(self) -> Result<Self::Ok, Self::Err>; } // Note: all the methods in this trait are infallible, which may be surprising. |
