Skip to main content

DumpOptions

Struct DumpOptions 

Source
pub struct DumpOptions {
    pub mode: DumpMode,
    pub include: Option<HashSet<String>>,
    pub exclude: Option<HashSet<String>>,
    pub by_alias: bool,
    pub exclude_unset: bool,
    pub exclude_defaults: bool,
    pub exclude_none: bool,
    pub exclude_computed_fields: bool,
    pub round_trip: bool,
    pub indent: Option<usize>,
}
Expand description

Options for model_dump() and model_dump_json().

Controls the serialization behavior.

Fields§

§mode: DumpMode

Output mode: Json or Python (Rust native).

Note: This option is currently NOT IMPLEMENTED. In Pydantic, mode='json' returns JSON-compatible types (strings for dates) while mode='python' returns native Python types (datetime objects). In Rust with serde, type serialization is determined by Serialize implementations, so both modes currently produce identical serde_json::Value output.

§include: Option<HashSet<String>>

Only include these fields (if Some)

§exclude: Option<HashSet<String>>

Exclude these fields

§by_alias: bool

Use field aliases in output.

When true, sql_model_dump() will rename fields to their serialization_alias (or alias as fallback) in the output.

§exclude_unset: bool

Exclude fields that were not explicitly set.

Note: This option is currently NOT IMPLEMENTED. It is defined for API compatibility with Pydantic but has no effect. Full implementation requires compile-time code generation to track which fields were explicitly provided during construction (a fields_set: HashSet<String>). This differs from exclude_defaults which compares current values to known defaults.

Pydantic semantics: If a field has a default value and the user explicitly sets it to that default, it should still be included (it was “set”). With exclude_defaults, it would be excluded regardless of whether it was explicitly provided.

§exclude_defaults: bool

Exclude fields with default values

§exclude_none: bool

Exclude fields with None/null values

§exclude_computed_fields: bool

Exclude computed fields (for future computed_field support)

§round_trip: bool

Enable round-trip mode (preserves types for re-parsing).

Note: This option is currently NOT IMPLEMENTED. In Pydantic, round_trip mode serializes values in a way that can be deserialized back to the exact same model. In Rust with serde, round-trip fidelity is generally handled by the Serialize/Deserialize implementations.

§indent: Option<usize>

Indentation for JSON output (None = compact, Some(n) = n spaces)

Implementations§

Source§

impl DumpOptions

Source

pub fn new() -> Self

Create new default options.

Source

pub fn json(self) -> Self

Set output mode to JSON.

Source

pub fn python(self) -> Self

Set output mode to Python (Rust native).

Source

pub fn include( self, fields: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Set fields to include.

Source

pub fn exclude( self, fields: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Set fields to exclude.

Source

pub fn by_alias(self) -> Self

Enable by_alias mode.

Source

pub fn exclude_unset(self) -> Self

Enable exclude_unset mode.

Source

pub fn exclude_defaults(self) -> Self

Enable exclude_defaults mode.

Source

pub fn exclude_none(self) -> Self

Enable exclude_none mode.

Source

pub fn exclude_computed_fields(self) -> Self

Enable exclude_computed_fields mode.

Source

pub fn round_trip(self) -> Self

Enable round_trip mode.

Source

pub fn indent(self, spaces: usize) -> Self

Set indentation for JSON output.

When set, JSON output will be pretty-printed with the specified number of spaces for indentation. When None (default), JSON is compact.

Trait Implementations§

Source§

impl Clone for DumpOptions

Source§

fn clone(&self) -> DumpOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DumpOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DumpOptions

Source§

fn default() -> DumpOptions

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more