pub struct JsonFormat {
pub pretty: bool,
}Expand description
Custom JSON format handler.
This format preserves all narrative structure and metadata, making it ideal for storing narratives in databases or exchanging between systems.
§Example
use spatial_narrative::io::{JsonFormat, Format};
use spatial_narrative::prelude::*;
let format = JsonFormat::new();
let event = Event::builder()
.location(Location::new(40.7128, -74.006))
.timestamp(Timestamp::now())
.text("Something happened")
.build();
let narrative = Narrative::builder()
.title("My Story")
.event(event)
.build();
let json = format.export_str(&narrative).unwrap();
let restored = format.import_str(&json).unwrap();
assert_eq!(restored.events().len(), 1);Fields§
§pretty: boolWhether to pretty-print the JSON output
Implementations§
Trait Implementations§
Source§impl Clone for JsonFormat
impl Clone for JsonFormat
Source§fn clone(&self) -> JsonFormat
fn clone(&self) -> JsonFormat
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for JsonFormat
impl Debug for JsonFormat
Source§impl Default for JsonFormat
impl Default for JsonFormat
Source§fn default() -> JsonFormat
fn default() -> JsonFormat
Returns the “default value” for a type. Read more
Source§impl Format for JsonFormat
impl Format for JsonFormat
Source§fn import<R: Read>(&self, reader: R) -> Result<Narrative>
fn import<R: Read>(&self, reader: R) -> Result<Narrative>
Import a narrative from a reader. Read more
Source§fn export<W: Write>(&self, narrative: &Narrative, writer: W) -> Result<()>
fn export<W: Write>(&self, narrative: &Narrative, writer: W) -> Result<()>
Export a narrative to a writer. Read more
Auto Trait Implementations§
impl Freeze for JsonFormat
impl RefUnwindSafe for JsonFormat
impl Send for JsonFormat
impl Sync for JsonFormat
impl Unpin for JsonFormat
impl UnwindSafe for JsonFormat
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