Struct WriterBuilder
pub struct WriterBuilder(EncoderOptions);
Expand description
JSON writer builder.
Tuple Fields§
§0: EncoderOptions
Implementations§
§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 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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request