Skip to main content

RustType

Enum RustType 

Source
#[non_exhaustive]
pub enum RustType {
Show 19 variants Bool, I32, I64, U32, U64, F64, String, Value, Date, DateTime, Uuid, Bytes, Vec(Box<RustType>), Map(Box<RustType>), Option(Box<RustType>), Boxed(Box<RustType>), Named(String), External { module: String, name: String, }, Verbatim { text: String, derives: ForeignDerives, },
}
Expand description

A Rust type expression usable in field/alias position.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Bool

bool.

§

I32

i32.

§

I64

i64.

§

U32

u32.

§

U64

u64.

§

F64

f64.

§

String

String.

§

Value

serde_json::Value (free-form / empty schema).

§

Date

chrono::NaiveDate (format: date).

§

DateTime

chrono::DateTime<chrono::Utc> (format: date-time).

§

Uuid

uuid::Uuid (format: uuid).

§

Bytes

Vec<u8> (format: byte/binary).

§

Vec(Box<RustType>)

Vec<T>.

§

Map(Box<RustType>)

std::collections::HashMap<String, T>.

§

Option(Box<RustType>)

Option<T>.

§

Boxed(Box<RustType>)

Box<T>, added by the recursion pass to give a cyclic type a size.

Nothing in a schema asks for this. lower::recurse inserts it where a type would otherwise hold itself, directly or through other types.

§

Named(String)

A reference to a named (generated or external) type.

§

External

A reference to a type from an import-mapped module: module::Name.

Generated by another run of this generator, so it derives all three non-serde traits and carries no ForeignDerives.

Fields

§module: String
§name: String
§

Verbatim

A verbatim type expression from an x-rust-type extension, with what its x-rust-derive says the target implements.

Fields

§text: String

The Rust type expression, emitted as written.

§derives: ForeignDerives

Which of Debug, Clone, PartialEq the target satisfies.

Implementations§

Source§

impl RustType

Source

pub fn optional(self) -> RustType

Wrap this type in Option<..>.

Source

pub fn is_option(&self) -> bool

Whether this type is an Option<..> (for which skip_serializing_if = "Option::is_none" is valid).

Source

pub fn innermost(&self) -> &RustType

The type inside any Option or Box wrapper.

A Vec and a Map are not wrappers here. Each carries keywords of its own, so a rule reads the collection and not an element.

Source

pub fn is_scalar(&self) -> bool

Whether this is a scalar the generated code compares with ==.

Source

pub fn label(&self) -> String

The type as text, for an error message.

Emission goes through emit::emit_type, which builds tokens. This gives a reader the same type in a message that the lowering stage can write, where no token stream exists yet.

Source

pub fn verbatim(text: impl Into<String>) -> RustType

An x-rust-type target whose x-rust-derive is absent, so it claims all three non-serde traits. The common case, and the shape every test that does not test this feature wants.

Trait Implementations§

Source§

impl Clone for RustType

Source§

fn clone(&self) -> RustType

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 RustType

Source§

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

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

impl Eq for RustType

Source§

impl PartialEq for RustType

Source§

fn eq(&self, other: &RustType) -> 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 RustType

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<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> 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.