Struct ion_binary_rs::IonEncoder
source · pub struct IonEncoder { /* private fields */ }
Expand description
Allows to binary encode one or multiple IonValue.
Given how Ion format works there are two methods in order to use this utility.
add
allows to add IonValue to the buffer to later encoding.encode
takes all biffered values and encodes them, generating the symbol’s table and the ion header. It returns a Vec.
use ion_binary_rs::{IonEncoder, IonParser, IonValue};
use std::collections::HashMap;
let mut ion_struct = HashMap::new();
ion_struct.insert("Model".to_string(), IonValue::String("CLK 350".to_string()));
ion_struct.insert("Type".to_string(), IonValue::String("Sedan".to_string()));
ion_struct.insert("Color".to_string(), IonValue::String("White".to_string()));
ion_struct.insert(
"VIN".to_string(),
IonValue::String("1C4RJFAG0FC625797".to_string()),
);
ion_struct.insert("Make".to_string(), IonValue::String("Mercedes".to_string()));
ion_struct.insert("Year".to_string(), IonValue::Integer(2019));
let ion_value = IonValue::Struct(ion_struct);
let mut encoder = IonEncoder::new();
encoder.add(ion_value.clone());
let bytes = encoder.encode();
let resulting_ion_value = IonParser::new(&bytes[..]).consume_value().unwrap().0;
assert_eq!(ion_value, resulting_ion_value);
Implementations§
Trait Implementations§
source§impl Debug for IonEncoder
impl Debug for IonEncoder
Auto Trait Implementations§
impl RefUnwindSafe for IonEncoder
impl Send for IonEncoder
impl Sync for IonEncoder
impl Unpin for IonEncoder
impl UnwindSafe for IonEncoder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more