Auto

Enum Auto 

Source
pub enum Auto<T> {
    Fixed(T),
    Auto,
}
Available on crate feature db only.
Expand description

A wrapper over a value that can be either a fixed value or be automatically generated by the database.

This is primarily used for auto-incrementing primary keys.

§Examples

use cot::db::{Auto, Model, model};

#[model]
struct MyModel {
    #[model(primary_key)]
    id: Auto<i32>,
}



let database = Database::new("sqlite::memory:").await?;

let mut my_model = MyModel { id: Auto::auto() };
my_model.save(&database).await?;
assert!(matches!(my_model.id, Auto::Fixed(_)));

Variants§

§

Fixed(T)

A fixed value.

§

Auto

A value that will be automatically generated by the database.

Implementations§

Source§

impl<T> Auto<T>

Source

pub const fn auto() -> Self

Creates a new Auto instance that is automatically generated by the database.

§Examples
use cot::db::Auto;

let auto = Auto::<i32>::auto();
assert!(matches!(auto, Auto::Auto));
Source

pub const fn fixed(value: T) -> Self

Creates a new Auto instance with a fixed value.

§Examples
use cot::db::Auto;

let auto = Auto::fixed(42);
assert!(matches!(auto, Auto::Fixed(42)));
assert_eq!(auto.unwrap(), 42);
Source

pub fn unwrap(self) -> T

Returns the value, if the object is the Auto::Fixed variant; panics otherwise.

This is an equivalent of Option::unwrap.

§Panics

If the object is the Auto::Auto variant.

§Examples
use cot::db::Auto;

let auto = Auto::fixed(42);
assert_eq!(auto.unwrap(), 42);
Source

pub fn expect(self, message: &str) -> T

Returns the value, if the object is the Auto::Fixed variant; panics with given message otherwise.

This is an equivalent of Option::expect.

§Panics

If the object is the Auto::Auto variant.

§Examples
use cot::db::Auto;

let auto = Auto::fixed(42);
assert_eq!(auto.expect("expected a fixed value"), 42);

Trait Implementations§

Source§

impl<T: AsFormField> AsFormField for Auto<T>

Source§

type Type = <T as AsFormField>::Type

The form field type associated with the field.
Source§

fn new_field( options: FormFieldOptions, custom_options: <Self::Type as FormField>::CustomOptions, ) -> Self::Type

Creates a new form field with the given options and custom options. Read more
Source§

fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
where Self: Sized,

Validates the value of the field and converts it to the final type. This method should return an error if the value is invalid. Read more
Source§

fn to_field_value(&self) -> String

Returns self as a value that can be set with FormField::set_value.
Source§

impl<T: Clone> Clone for Auto<T>

Source§

fn clone(&self) -> Auto<T>

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<T: DatabaseField> DatabaseField for Auto<T>

Source§

const NULLABLE: bool = T::NULLABLE

Whether the field can be NULL in the database. Read more
Source§

const TYPE: ColumnType = T::TYPE

The type of the column in the database as one of the variants of the ColumnType enum. Read more
Source§

impl<T> Debug for Auto<T>
where T: Debug,

Source§

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

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

impl<T> Default for Auto<T>

Source§

fn default() -> Self

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

impl<T: Display> Display for Auto<T>

Source§

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

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

impl<T> From<T> for Auto<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: DatabaseField> FromDbValue for Auto<T>

Source§

fn from_sqlite(value: SqliteValueRef<'_>) -> Result<Self>
where Self: Sized,

Available on crate feature sqlite only.
Converts the given SQLite database value to a Rust value. Read more
Source§

fn from_postgres(value: PostgresValueRef<'_>) -> Result<Self>
where Self: Sized,

Available on crate feature postgres only.
Converts the given PostgreSQL database value to a Rust value. Read more
Source§

fn from_mysql(value: MySqlValueRef<'_>) -> Result<Self>
where Self: Sized,

Available on crate feature mysql only.
Converts the given MySQL database value to a Rust value. Read more
Source§

impl<T: FromStr> FromStr for Auto<T>

Source§

type Err = <T as FromStr>::Err

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<T: Hash> Hash for Auto<T>

Source§

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

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<T: PartialEq> PartialEq for Auto<T>

Source§

fn eq(&self, other: &Auto<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: DatabaseField> ToDbFieldValue for Auto<T>

Source§

fn to_db_field_value(&self) -> DbFieldValue

Converts the Rust value to a DbFieldValue that indicates whether the value should be automatically generated by the database, or contains a specific, explicitly provided value.
Source§

impl<T: Copy> Copy for Auto<T>

Source§

impl<T: Eq> Eq for Auto<T>

Source§

impl<T: PrimaryKey> PrimaryKey for Auto<T>

Source§

impl<T> StructuralPartialEq for Auto<T>

Auto Trait Implementations§

§

impl<T> Freeze for Auto<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Auto<T>
where T: RefUnwindSafe,

§

impl<T> Send for Auto<T>
where T: Send,

§

impl<T> Sync for Auto<T>
where T: Sync,

§

impl<T> Unpin for Auto<T>
where T: Unpin,

§

impl<T> UnwindSafe for Auto<T>
where T: UnwindSafe,

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: Rng + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> IntoApi for T

Source§

fn into_api<A>(self) -> UseApi<T, A>

into UseApi
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoField<Auto<T>> for T

Source§

fn into_field(self) -> Auto<T>

Available on crate feature db only.
Converts the type to the field type.
Source§

impl<T> IntoField<T> for T
where T: ToDbFieldValue,

Source§

fn into_field(self) -> T

Available on crate feature db only.
Converts the type to the field type.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,