Trait ion_c_sys::writer::IonCWriter
source · pub trait IonCWriter<'a>: IonCValueWriter + IonCAnnotationsFieldWriter {
// Required method
fn finish(&mut self) -> IonCResult<usize>;
// Provided methods
fn field<'b, 'c>(
&'b mut self,
field: &'c str
) -> IonCAnnotationsFieldWriterContext<'b, 'c, Self> { ... }
fn annotations<'b, 'c>(
&'b mut self,
annotations: &'c [&'c str]
) -> IonCAnnotationsFieldWriterContext<'b, 'c, Self> { ... }
}
Expand description
The writing API for Ion C.
See also:
Usage
// a buffer to write to
let mut buf = vec![0; 12];
// borrow the buffer and do some writing!
let len = {
// write in binary
let mut writer = IonCWriterHandle::new_buf_mode(buf.as_mut(), WriterMode::Binary)?;
// write something
writer.write_i64(4)?;
// finish up the writing
writer.finish()?
// handle implements Drop, so we're good to go!
};
assert_eq!(b"\xE0\x01\x00\xEA\x21\x04", &buf[0..len]);
Required Methods§
sourcefn finish(&mut self) -> IonCResult<usize>
fn finish(&mut self) -> IonCResult<usize>
Finalizes writing for the writer and returns the amount of bytes written.
Provided Methods§
sourcefn field<'b, 'c>(
&'b mut self,
field: &'c str
) -> IonCAnnotationsFieldWriterContext<'b, 'c, Self>
fn field<'b, 'c>( &'b mut self, field: &'c str ) -> IonCAnnotationsFieldWriterContext<'b, 'c, Self>
Returns a lifetime safe writing context for a field.
Usage
let mut buf = vec![0; 128];
let len = {
let mut writer = IonCWriterHandle::new_buf_mode(buf.as_mut_slice(), WriterMode::Binary)?;
writer.start_container(ION_TYPE_STRUCT)?;
{
writer.field("name").write_string("kumo")?;
}
writer.finish_container()?;
writer.finish()?
};
assert_eq!(b"\xE0\x01\x00\xEA\xD6\x84\x84kumo", &buf[0..len]);
sourcefn annotations<'b, 'c>(
&'b mut self,
annotations: &'c [&'c str]
) -> IonCAnnotationsFieldWriterContext<'b, 'c, Self>
fn annotations<'b, 'c>( &'b mut self, annotations: &'c [&'c str] ) -> IonCAnnotationsFieldWriterContext<'b, 'c, Self>
Returns a lifetime safe writing context for annotations.
Usage
let mut buf = vec![0; 128];
let len = {
let mut writer = IonCWriterHandle::new_buf_mode(buf.as_mut_slice(), WriterMode::Text)?;
writer.annotations(&["a", "b", "c"]).start_container(ION_TYPE_STRUCT)?;
{
writer.field("name").annotations(&["def"]).write_string("kumo")?;
writer.annotations(&["ghi"]).field("type").write_symbol("dog")?;
}
writer.finish_container()?;
writer.finish()?
};
assert_eq!("a::b::c::{name:def::\"kumo\",type:ghi::dog}", str::from_utf8(&buf[0..len])?);