Struct WriterBuilder
pub struct WriterBuilder(EncoderOptions);Expand description
JSON writer builder.
Tuple Fields§
§0: EncoderOptionsImplementations§
§impl WriterBuilder
impl WriterBuilder
pub fn new() -> WriterBuilder
pub fn new() -> WriterBuilder
Create a new builder for configuring JSON writing options.
§Example
fn example() -> Writer<File, LineDelimited> {
let file = File::create("target/out.json").unwrap();
// create a builder that keeps keys with null values
let builder = WriterBuilder::new().with_explicit_nulls(true);
let writer = builder.build::<_, LineDelimited>(file);
writer
}pub fn explicit_nulls(&self) -> bool
pub fn explicit_nulls(&self) -> bool
Returns true if this writer is configured to keep keys with null values.
pub fn with_explicit_nulls(self, explicit_nulls: bool) -> WriterBuilder
pub fn with_explicit_nulls(self, explicit_nulls: bool) -> WriterBuilder
Set whether to keep keys with null values, or to omit writing them.
For example, with LineDelimited format:
Skip nulls (set to false):
{"foo":1}
{"foo":1,"bar":2}
{}Keep nulls (set to true):
{"foo":1,"bar":null}
{"foo":1,"bar":2}
{"foo":null,"bar":null}Default is to skip nulls (set to false). If struct_mode == ListOnly,
nulls will be written explicitly regardless of this setting.
pub fn struct_mode(&self) -> StructMode
pub fn struct_mode(&self) -> StructMode
Returns if this writer is configured to write structs as JSON Objects or Arrays.
pub fn with_struct_mode(self, struct_mode: StructMode) -> WriterBuilder
pub fn with_struct_mode(self, struct_mode: StructMode) -> WriterBuilder
Set the StructMode for the writer, which determines whether structs
are encoded to JSON as objects or lists. For more details refer to the
enum documentation. Default is to use ObjectOnly. If this is set to
ListOnly, nulls will be written explicitly regardless of the
explicit_nulls setting.
pub fn with_encoder_factory(
self,
factory: Arc<dyn EncoderFactory>,
) -> WriterBuilder
pub fn with_encoder_factory( self, factory: Arc<dyn EncoderFactory>, ) -> WriterBuilder
Set an encoder factory to use when creating encoders for writing JSON.
This can be used to override how some types are encoded or to provide a fallback for types that are not supported by the default encoder.
pub fn with_date_format(self, format: String) -> WriterBuilder
pub fn with_date_format(self, format: String) -> WriterBuilder
Set the JSON file’s date format
pub fn with_datetime_format(self, format: String) -> WriterBuilder
pub fn with_datetime_format(self, format: String) -> WriterBuilder
Set the JSON file’s datetime format
pub fn with_time_format(self, format: String) -> WriterBuilder
pub fn with_time_format(self, format: String) -> WriterBuilder
Set the JSON file’s time format
pub fn with_timestamp_format(self, format: String) -> WriterBuilder
pub fn with_timestamp_format(self, format: String) -> WriterBuilder
Set the JSON file’s timestamp format
pub fn with_timestamp_tz_format(self, tz_format: String) -> WriterBuilder
pub fn with_timestamp_tz_format(self, tz_format: String) -> WriterBuilder
Set the JSON file’s timestamp tz format
pub fn build<W, F>(self, writer: W) -> Writer<W, F>where
W: Write,
F: JsonFormat,
pub fn build<W, F>(self, writer: W) -> Writer<W, F>where
W: Write,
F: JsonFormat,
Create a new Writer with specified JsonFormat and builder options.
Trait Implementations§
§impl Clone for WriterBuilder
impl Clone for WriterBuilder
§fn clone(&self) -> WriterBuilder
fn clone(&self) -> WriterBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for WriterBuilder
impl Debug for WriterBuilder
§impl Default for WriterBuilder
impl Default for WriterBuilder
§fn default() -> WriterBuilder
fn default() -> WriterBuilder
Auto Trait Implementations§
impl Freeze for WriterBuilder
impl !RefUnwindSafe for WriterBuilder
impl Send for WriterBuilder
impl Sync for WriterBuilder
impl Unpin for WriterBuilder
impl !UnwindSafe for WriterBuilder
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more