Auto merge of #51356 - Zoxc:encode-cleanup, r=michaelwoerister
Make opaque::Encoder append-only and make it infallible
This commit is contained in:
commit
ed0350e945
12 changed files with 80 additions and 118 deletions
|
|
@ -41,17 +41,16 @@ enum WireProtocol {
|
|||
fn encode_json<T: Encodable>(val: &T, wr: &mut Cursor<Vec<u8>>) {
|
||||
write!(wr, "{}", json::as_json(val));
|
||||
}
|
||||
fn encode_opaque<T: Encodable>(val: &T, wr: &mut Cursor<Vec<u8>>) {
|
||||
fn encode_opaque<T: Encodable>(val: &T, wr: Vec<u8>) {
|
||||
let mut encoder = opaque::Encoder::new(wr);
|
||||
val.encode(&mut encoder);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let target = Foo{baz: false,};
|
||||
let mut wr = Cursor::new(Vec::new());
|
||||
let proto = WireProtocol::JSON;
|
||||
match proto {
|
||||
WireProtocol::JSON => encode_json(&target, &mut wr),
|
||||
WireProtocol::Opaque => encode_opaque(&target, &mut wr)
|
||||
WireProtocol::JSON => encode_json(&target, &mut Cursor::new(Vec::new())),
|
||||
WireProtocol::Opaque => encode_opaque(&target, Vec::new())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue