pub struct FormattingConfig {
pub id_on_primitives: bool,
pub id_on_tuples: bool,
pub id_on_containers: bool,
pub id_on_seqs: bool,
pub id_on_maps: bool,
pub width_limit: Option<u16>,
}
Expand description
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<u16>
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§
Source§impl Clone for FormattingConfig
impl Clone for FormattingConfig
Source§fn clone(&self) -> FormattingConfig
fn clone(&self) -> FormattingConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for FormattingConfig
impl Debug for FormattingConfig
Source§impl Default for FormattingConfig
impl Default for FormattingConfig
Source§impl PartialEq for FormattingConfig
impl PartialEq for FormattingConfig
impl Copy for FormattingConfig
impl StructuralPartialEq for FormattingConfig
Auto Trait Implementations§
impl Freeze for FormattingConfig
impl RefUnwindSafe for FormattingConfig
impl Send for FormattingConfig
impl Sync for FormattingConfig
impl Unpin for FormattingConfig
impl UnwindSafe for FormattingConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
Source§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
Source§impl<T> PipeDeref for T
impl<T> PipeDeref for T
Source§impl<T> PipeRef for T
impl<T> PipeRef for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
Source§fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
tap
in debug builds, and does nothing in release builds.Source§fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
Source§fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
tap_mut
in debug builds, and does nothing in release builds.Source§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
Source§fn tap_ref<F, R>(self, func: F) -> Self
fn tap_ref<F, R>(self, func: F) -> Self
Source§fn tap_ref_dbg<F, R>(self, func: F) -> Self
fn tap_ref_dbg<F, R>(self, func: F) -> Self
tap_ref
in debug builds, and does nothing in release builds.Source§fn tap_ref_mut<F, R>(self, func: F) -> Self
fn tap_ref_mut<F, R>(self, func: F) -> Self
Source§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
Source§fn tap_borrow<F, R>(self, func: F) -> Self
fn tap_borrow<F, R>(self, func: F) -> Self
Source§fn tap_borrow_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_dbg<F, R>(self, func: F) -> Self
tap_borrow
in debug builds, and does nothing in release builds.Source§fn tap_borrow_mut<F, R>(self, func: F) -> Self
fn tap_borrow_mut<F, R>(self, func: F) -> Self
Source§impl<T> TapDeref for T
impl<T> TapDeref for T
Source§fn tap_deref_dbg<F, R>(self, func: F) -> Self
fn tap_deref_dbg<F, R>(self, func: F) -> Self
tap_deref
in debug builds, and does nothing in release builds.Source§fn tap_deref_mut<F, R>(self, func: F) -> Self
fn tap_deref_mut<F, R>(self, func: F) -> Self
self
for modification.