[−][src]Struct kserd::fmt::FormattingConfig
Configuration of how a Kserd
is to be formatted.
Generally the default values should be used when displaying a Kserd
. If the Kserd
is being
used for serialisation of data then the default is not recommended. There are constructor
methods that can be used that better capture round-trip data conversions.
The likely field that would be changed is width_limit
. Altering this value can allow for more
or less verbosity as to the formatter's taste.
Example
use kserd::fmt::FormattingConfig; let kserd = Kserd::new_cntr(vec![ ("a", Kserd::new_num(101)), ("b", Kserd::new_num(3.14)), ]).unwrap(); let fmt = kserd.as_str_with_config(FormattingConfig { width_limit: None, // None means no limit, so all inline ..Default::default() }); assert_eq!(&fmt, "(a = 101, b = 3.14)"); let fmt = kserd.as_str_with_config(FormattingConfig { width_limit: Some(16), // This force a concise layout ..Default::default() }); assert_eq!(&fmt, "( a = 101 b = 3.14 )" ); let fmt = kserd.as_str_with_config(FormattingConfig { width_limit: Some(0), // Always will be verbose where applicable ..Default::default() }); assert_eq!(&fmt, "a = 101 b = 3.14 ");
Fields
id_on_primitives: bool
Display the identity on primitive values. Default is false.
Example
use kserd::fmt::FormattingConfig; let kserd = Kserd::new_cntr(vec![ ("unit", Kserd::new_unit()), ("bool", Kserd::new_bool(true)), ("number", Kserd::new_num(1)), ("float", Kserd::new_num(3.14)), ("str", Kserd::new_str("Hello")), ("barr", Kserd::new_barr(&[0, 1, 2])), ]).unwrap(); let show_prims = FormattingConfig { id_on_primitives: true, width_limit: Some(0), ..Default::default() }; assert_eq!(&kserd.as_str_with_config(show_prims), r#"barr = <barr> b91':CQA' bool = <bool> true float = <f64> 3.14 number = <i32> 1 str = <str> "Hello" unit = () "#);
id_on_tuples: bool
Display the identity on tuple values. Default is true.
Example
use kserd::fmt::FormattingConfig; let kserd = Kserd::with_id("a-tuple", Value::Tuple(vec![])).unwrap(); let show_tuples = FormattingConfig { id_on_tuples: true, ..Default::default() }; assert_eq!( &kserd.as_str_with_config(show_tuples), "a-tuple ()" );
id_on_containers: bool
Display the identity on container values. Default is true.
Example
use kserd::fmt::FormattingConfig; let kserd = Kserd::with_id("a-cntr", Value::new_cntr(Vec::<(&str, _)>::new()).unwrap()) .unwrap(); let show_containers = FormattingConfig { id_on_containers: true, ..Default::default() }; assert_eq!( &kserd.as_str_with_config(show_containers), "a-cntr ()" );
id_on_seqs: bool
Display the identity on sequences. Default is false.
Example
use kserd::fmt::FormattingConfig; let kserd = Kserd::with_id("a-seq", Value::Seq(vec![])).unwrap(); let show_seqs = FormattingConfig { id_on_seqs: true, ..Default::default() }; assert_eq!( &kserd.as_str_with_config(show_seqs), "a-seq []" );
id_on_maps: bool
Display the identity on maps. Default is false.
Example
use kserd::fmt::FormattingConfig; let kserd = Kserd::with_id("a-map", Value::new_map(vec![])).unwrap(); let show_maps = FormattingConfig { id_on_maps: true, ..Default::default() }; assert_eq!( &kserd.as_str_with_config(show_maps), "a-map { }" );
width_limit: Option<usize>
The column limit in characters.
The default is Some(60)
.
When a FormattingConfig
is applied to a Kserd
, the contents tries to use inline
formatting as much as possible. If the inline format is too wide, then a concise format is
used. If the concise format is still too wide, the verbose formatting is used.
Setting to None
means a limit is never reached and all formatting is done inline.
Setting to Some(0)
means the formatting always reaches a limit and each Kserd
will
be formatted at it's maximum verbosity.
Trait Implementations
impl Clone for FormattingConfig
[src]
fn clone(&self) -> FormattingConfig
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for FormattingConfig
[src]
impl Default for FormattingConfig
[src]
Auto Trait Implementations
impl RefUnwindSafe for FormattingConfig
impl Send for FormattingConfig
impl Sync for FormattingConfig
impl Unpin for FormattingConfig
impl UnwindSafe for FormattingConfig
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,