pub struct Writer { /* private fields */ }Expand description
Writes the text form piece by piece, without a Value in between. A
list or map is given its length, then that many values (a map’s each
after its key); it closes by itself after the last, so there are no
end calls. The pretty form puts one entry per line.
let mut w = substrate_data::text::Writer::new();
w.map(2).key("id").str("docs/intro").key("pages").list(2);
w.int(1).int(2);
assert_eq!(w.finish(), r#"{"id":"docs/intro","pages":[1,2]}"#);Implementations§
Source§impl Writer
impl Writer
Sourcepub fn pretty() -> Self
pub fn pretty() -> Self
A writer of text indented by two spaces, one entry per line, ending with a newline.
Sourcepub fn float(&mut self, f: f64) -> &mut Self
pub fn float(&mut self, f: f64) -> &mut Self
A float, in the shortest spelling that reads back as it and as a
float; null for a NaN or an infinity.
Sourcepub fn str(&mut self, s: &str) -> &mut Self
pub fn str(&mut self, s: &str) -> &mut Self
A string, as spelled (the text form has no other kind of text).
Sourcepub fn reference(&mut self, kind: &str, id: &str) -> &mut Self
pub fn reference(&mut self, kind: &str, id: &str) -> &mut Self
A reference, as its string form @kind:id.
Sourcepub fn bytes(&mut self, bytes: &[u8]) -> &mut Self
pub fn bytes(&mut self, bytes: &[u8]) -> &mut Self
Bytes, as their string form @bytes:<base64>.
Sourcepub fn map(&mut self, len: usize) -> &mut Self
pub fn map(&mut self, len: usize) -> &mut Self
A map of len entries (key, then its value), which follow.
Sourcepub fn key(&mut self, key: &str) -> &mut Self
pub fn key(&mut self, key: &str) -> &mut Self
The key of the map’s next entry; its value follows.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Writer
impl RefUnwindSafe for Writer
impl Send for Writer
impl Sync for Writer
impl Unpin for Writer
impl UnsafeUnpin for Writer
impl UnwindSafe for Writer
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