Skip to main content

Field

Struct Field 

Source
pub struct Field { /* private fields */ }
Expand description

One named field: a type, whether it may be null and whether it must be present, its constraints, and optionally the source’s own name for the type, a description and metadata.

Implementations§

Source§

impl Field

Source

pub fn new(name: impl Into<String>, data_type: DataType) -> Field

A nullable, optional field.

Source

pub fn nullable(self, nullable: bool) -> Field

Whether the field may be null (default true).

Source

pub fn required(self, required: bool) -> Field

Whether a value must be present (default false): JSON Schema’s required, SQL’s NOT NULL, a non-nullable Arrow field.

Source

pub fn with_native_type(self, native: impl Into<String>) -> Field

The source format’s own name for the type, kept as written (Int32, VARCHAR(20), string | null). A schema tree shows it in place of the model’s type.

Source

pub fn with_description(self, description: impl Into<String>) -> Field

A description, as the source gives it.

Source

pub fn with_type(self, data_type: DataType) -> Field

Replace the type.

Source

pub fn with_constraint(self, constraint: Constraint) -> Field

Add a constraint.

Source

pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Field

Add a metadata entry (Arrow’s field metadata).

Source

pub fn with_kind(self, kind: FieldKind) -> Field

How the field relates to its parent (default FieldKind::Field).

Source

pub fn with_reference(self, reference: impl Into<String>) -> Field

The named definition the type was found through (#/$defs/item).

Source

pub fn with_unexpanded(self, unexpanded: Unexpanded) -> Field

Mark the type as named by a reference that is not drawn in place.

Source

pub fn elided(self, elided: bool) -> Field

Mark the children as left out, at a depth limit.

Source

pub fn name(&self) -> &str

The name.

Source

pub fn data_type(&self) -> &DataType

The type.

Source

pub fn data_type_mut(&mut self) -> &mut DataType

The type, to change in place.

Source

pub fn is_nullable(&self) -> bool

Whether the field may be null.

Source

pub fn is_required(&self) -> bool

Whether a value must be present.

Source

pub fn native_type(&self) -> Option<&str>

The source’s own type name, if one was recorded.

Source

pub fn type_label(&self) -> String

The type as a tree shows it: the native type, else the model’s.

Source

pub fn description(&self) -> Option<&str>

The description, if any.

Source

pub fn constraints(&self) -> &[Constraint]

The constraints, in the order the source gives them.

Source

pub fn constraints_mut(&mut self) -> &mut Vec<Constraint>

The constraints, to change in place.

Source

pub fn constraint(&self, key: &str) -> Option<&Constraint>

The first constraint with key (Constraint::key).

Source

pub fn metadata(&self) -> &[(String, String)]

The metadata entries, in order.

Source

pub fn enum_values(&self) -> Option<&[Literal]>

The listed values, when the field is an enum.

Source

pub fn default_value(&self) -> Option<&Literal>

The default value, if any.

Source

pub fn is_primary_key(&self) -> bool

Whether the field is (part of) the primary key.

Source

pub fn is_unique(&self) -> bool

Whether the field’s values are unique on their own.

Source

pub fn references(&self) -> Option<&ForeignKey>

What the field refers to, if it is a foreign key.

Source

pub fn kind(&self) -> FieldKind

How the field relates to its parent.

Source

pub fn reference(&self) -> Option<&str>

The named definition the type was found through.

Source

pub fn unexpanded(&self) -> Option<&Unexpanded>

Why the type is not drawn in place, when it is not.

Source

pub fn is_elided(&self) -> bool

Whether the children were left out at a depth limit.

Source

pub fn children(&self) -> impl Iterator<Item = &Field>

The nested fields (DataType::children).

Trait Implementations§

Source§

impl Clone for Field

Source§

fn clone(&self) -> Field

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Field

Source§

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

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

impl Eq for Field

Source§

impl FromIterator<Field> for Schema

Source§

fn from_iter<I>(iter: I) -> Schema
where I: IntoIterator<Item = Field>,

Creates a value from an iterator. Read more
Source§

impl Hash for Field

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Field

Source§

fn eq(&self, other: &Field) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Field

Auto Trait Implementations§

§

impl Freeze for Field

§

impl RefUnwindSafe for Field

§

impl Send for Field

§

impl Sync for Field

§

impl Unpin for Field

§

impl UnsafeUnpin for Field

§

impl UnwindSafe for Field

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.