Struct jomini::TextWriter [−][src]
pub struct TextWriter<W, V> { /* fields omitted */ }
Expand description
Write data in PDS format.
Instantiated via TextWriterBuilder
Implementations
impl<W, V> TextWriter<W, V> where
W: Write,
V: WriteVisitor,
[src]
impl<W, V> TextWriter<W, V> where
W: Write,
V: WriteVisitor,
[src]pub fn into_inner(self) -> W
[src]
pub fn into_inner(self) -> W
[src]Consumes this Writer, returning the underlying writer
pub fn expecting_key(&self) -> bool
[src]
pub fn expecting_key(&self) -> bool
[src]Returns true if the next write event would be a key
pub fn write_object_start(&mut self) -> Result<(), Error>
[src]
pub fn write_object_start(&mut self) -> Result<(), Error>
[src]Write out the start of an object
pub fn write_array_start(&mut self) -> Result<(), Error>
[src]
pub fn write_array_start(&mut self) -> Result<(), Error>
[src]Write out the start of an array
pub fn write_bool(&mut self, data: bool) -> Result<(), Error>
[src]
pub fn write_bool(&mut self, data: bool) -> Result<(), Error>
[src]Write a boolean
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"hello")?; writer.write_bool(true)?; writer.write_unquoted(b"foo")?; writer.write_bool(false)?; assert_eq!(&out, b"hello=yes\nfoo=no\n");
pub fn write_operator(&mut self, data: Operator) -> Result<(), Error>
[src]
pub fn write_operator(&mut self, data: Operator) -> Result<(), Error>
[src]Write an non-equal operator
use jomini::{Operator, TextWriterBuilder}; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"a")?; writer.write_operator(Operator::LessThan)?; writer.write_unquoted(b"b")?; assert_eq!(&out, b"a < b\n");
pub fn write_unquoted(&mut self, data: &[u8]) -> Result<(), Error>
[src]
pub fn write_unquoted(&mut self, data: &[u8]) -> Result<(), Error>
[src]Write bytes directly to the writer.
The contents of the bytes are not checked, so it is up to the caller to ensure that the data is a valid unquoted field (no spaces or control characters).
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"a")?; writer.write_unquoted(b"b")?; assert_eq!(&out, b"a=b\n");
pub fn write_quoted(&mut self, data: &[u8]) -> Result<(), Error>
[src]
pub fn write_quoted(&mut self, data: &[u8]) -> Result<(), Error>
[src]Write a field to be encapsulated in quotes.
Unlike the unquoted variant, this method will inspect the data to ensure everything is properly escaped, like quotes and escape characters. And will trim trailing newlines.
Also if one tries to write a quoted field as a key this method will redirect to the unquoted variant
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_quoted(b"name")?; writer.write_quoted(br#"captain "joe" rogers"#)?; assert_eq!(&out, b"name=\"captain \\\"joe\\\" rogers\"\n");
pub fn write_i32(&mut self, data: i32) -> Result<(), Error>
[src]
pub fn write_i32(&mut self, data: i32) -> Result<(), Error>
[src]Write a signed 32bit integer.
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"stability")?; writer.write_i32(-3); assert_eq!(&out, b"stability=-3\n");
pub fn write_u32(&mut self, data: u32) -> Result<(), Error>
[src]
pub fn write_u32(&mut self, data: u32) -> Result<(), Error>
[src]Write an unsigned 32bit integer.
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"stability")?; writer.write_u32(3); assert_eq!(&out, b"stability=3\n");
pub fn write_u64(&mut self, data: u64) -> Result<(), Error>
[src]
pub fn write_u64(&mut self, data: u64) -> Result<(), Error>
[src]Write an unsigned 64bit integer.
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"seed")?; writer.write_u64(1000000000000); assert_eq!(&out, b"seed=1000000000000\n");
pub fn write_f32(&mut self, data: f32) -> Result<(), Error>
[src]
pub fn write_f32(&mut self, data: f32) -> Result<(), Error>
[src]Write a 32 bit floating point according to the visitor
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"morale")?; writer.write_f32(4.566); assert_eq!(&out, b"morale=4.566\n");
pub fn write_f64(&mut self, data: f64) -> Result<(), Error>
[src]
pub fn write_f64(&mut self, data: f64) -> Result<(), Error>
[src]Write a 64 bit floating point according to the visitor
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"strength")?; writer.write_f64(6790.35609); assert_eq!(&out, b"strength=6790.35609\n");
pub fn write_header(&mut self, header: &[u8]) -> Result<(), Error>
[src]
pub fn write_header(&mut self, header: &[u8]) -> Result<(), Error>
[src]Write a header.
It is undefined if the next commands do not write out the start of an array or object
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"color")?; writer.write_header(b"rgb")?; writer.write_array_start()?; writer.write_i32(100)?; writer.write_i32(200)?; writer.write_i32(50)?; writer.write_end()?; assert_eq!(&out, b"color=rgb {\n 100 200 50\n}\n");
pub fn write_date(&mut self, data: Date) -> Result<(), Error>
[src]
pub fn write_date(&mut self, data: Date) -> Result<(), Error>
[src]Write a date in the game format
use jomini::{common::Date, TextWriterBuilder}; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); let date = Date::new(1444, 12, 1).unwrap(); writer.write_unquoted(b"start")?; writer.write_date(date); assert_eq!(&out, b"start=1444.12.1\n");
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
[src]
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
[src]Write formatted data
Typically not invoked directly but instead through the write!
macro
use jomini::TextWriterBuilder; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_unquoted(b"start")?; write!(writer, "unknown_{}", 5)?; assert_eq!(&out, b"start=unknown_5\n");
pub fn write_tape(&mut self, tape: &TextTape<'_>) -> Result<(), Error>
[src]
pub fn write_tape(&mut self, tape: &TextTape<'_>) -> Result<(), Error>
[src]Writes a text tape
Formatting is not preserved.
use jomini::{TextTape, TextWriterBuilder}; let tape = TextTape::from_slice(b"hello=world")?; let mut out: Vec<u8> = Vec::new(); let mut writer = TextWriterBuilder::new().from_writer(&mut out); writer.write_tape(&tape)?; assert_eq!(&out, b"hello=world\n");
Trait Implementations
Auto Trait Implementations
impl<W, V> RefUnwindSafe for TextWriter<W, V> where
V: RefUnwindSafe,
W: RefUnwindSafe,
V: RefUnwindSafe,
W: RefUnwindSafe,
impl<W, V> Send for TextWriter<W, V> where
V: Send,
W: Send,
V: Send,
W: Send,
impl<W, V> Sync for TextWriter<W, V> where
V: Sync,
W: Sync,
V: Sync,
W: Sync,
impl<W, V> Unpin for TextWriter<W, V> where
V: Unpin,
W: Unpin,
V: Unpin,
W: Unpin,
impl<W, V> UnwindSafe for TextWriter<W, V> where
V: UnwindSafe,
W: UnwindSafe,
V: UnwindSafe,
W: UnwindSafe,