[−][src]Struct jsonxf::Formatter
Formatter
allows customizable pretty-printing, minimizing,
and other formatting tasks on JSON-encoded UTF-8 data in
string or stream format.
Example:
let mut fmt = jsonxf::Formatter::pretty_printer(); fmt.line_separator = String::from("\r\n"); assert_eq!( fmt.format("{\"a\":1}").unwrap(), "{\r\n \"a\": 1\r\n}" );
Fields
indent: String
Used for beginning-of-line indentation in arrays and objects.
line_separator: String
Used inside arrays and objects.
record_separator: String
Used between root-level arrays and objects.
after_colon: String
Used after a colon inside objects.
trailing_output: String
Used at very end of output.
Implementations
impl Formatter
[src]
pub fn pretty_printer() -> Formatter
[src]
Returns a Formatter set up for pretty-printing. Defaults to using two spaces of indentation, Unix newlines, and no whitespace at EOF.
Example:
assert_eq!( jsonxf::Formatter::pretty_printer().format("{\"a\":1}").unwrap(), "{\n \"a\": 1\n}" );
pub fn minimizer() -> Formatter
[src]
Returns a Formatter set up for minimizing. Defaults to using Unix newlines between records, and no whitespace at EOF.
Example:
assert_eq!( jsonxf::Formatter::minimizer().format("{ \"a\" : 1 }\n").unwrap(), "{\"a\":1}" );
pub fn format(&mut self, json_string: &str) -> Result<String, String>
[src]
Formats a string of JSON-encoded data.
Input must be valid JSON data in UTF-8 encoding.
Example:
let mut fmt = jsonxf::Formatter::pretty_printer(); fmt.indent = String::from("\t"); fmt.trailing_output = String::from("\n"); assert_eq!( fmt.format("{\"a\":1}").unwrap(), "{\n\t\"a\": 1\n}\n" );
pub fn format_stream(
&mut self,
input: &mut dyn Read,
output: &mut dyn Write
) -> Result<(), Error>
[src]
&mut self,
input: &mut dyn Read,
output: &mut dyn Write
) -> Result<(), Error>
Formats a stream of JSON-encoded data.
Input must be valid JSON data in UTF-8 encoding.
Example:
let mut fmt = jsonxf::Formatter::pretty_printer(); fmt.indent = String::from("\t"); fmt.trailing_output = String::from("\n"); match fmt.format_stream(&mut std::io::stdin(), &mut std::io::stdout()) { Ok(_) => { /* YAY */ }, Err(e) => { panic!(e.to_string()); } }
Auto Trait Implementations
impl RefUnwindSafe for Formatter
impl Send for Formatter
impl Sync for Formatter
impl Unpin for Formatter
impl UnwindSafe for Formatter
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,
pub 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, 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.
pub 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>,