Skip to main content

Attribute

Trait Attribute 

Source
pub trait Attribute: Sized {
    // Required methods
    fn schema() -> Value;
    fn read(value: &Value) -> Option<Self>;
    fn write(&self) -> Value;

    // Provided method
    fn required() -> bool { ... }
}
Expand description

A type a resource attribute can hold.

Required Methods§

Source

fn schema() -> Value

The JSON Schema for this type, as it appears under attributes.

Source

fn read(value: &Value) -> Option<Self>

Read the value out of a validated document.

None means the value was not of this type. The schema has already rejected anything ill-typed, so this fires only for a type whose schema is looser than its read — report it rather than defaulting.

Source

fn write(&self) -> Value

Write the value into a response’s attributes.

Provided Methods§

Source

fn required() -> bool

Whether the member may be absent.

Only Option overrides this. It drives the required list of the generated schema, so an optional field is one that may be omitted.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Attribute for String

String → {"type": "string"}.

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for bool

bool → {"type": "boolean"}.

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for f32

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for f64

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for i8

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for i16

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for i32

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for i64

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for u8

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for u16

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for u32

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl Attribute for u64

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

impl<T: Attribute> Attribute for Option<T>

Option<T> — the member may be absent, and null reads as None.

Source§

fn schema() -> Value

Source§

fn read(value: &Value) -> Option<Self>

Source§

fn write(&self) -> Value

Source§

fn required() -> bool

Implementors§