Skip to main content

EnumValues

Enum EnumValues 

Source
pub enum EnumValues {
    String(Vec<String>),
    Integer(Vec<NumValue>),
}
Expand description

The set of allowed values for an enum column, either string-based or integer-based.

String enums map to a native PostgreSQL ENUM type. Adding or removing values requires a database migration (ALTER TYPE).

Integer enums are stored as INTEGER. New variants can be added to the model without any database migration because the underlying column type never changes.

Choose integer enums for expandable value sets (roles, priorities) and string enums for stable, human-readable status fields.

Variants§

§

String(Vec<String>)

String enum: each variant is a plain string stored in a native DB enum type.

§

Integer(Vec<NumValue>)

Integer enum: each variant has an explicit numeric value stored as INTEGER.

Implementations§

Source§

impl EnumValues

Source

pub fn is_string(&self) -> bool

Check if this is a string enum

Source

pub fn is_integer(&self) -> bool

Check if this is an integer enum

Source

pub fn variant_names_joined(&self, separator: &str) -> String

Join every variant name with separator, writing straight into one buffer — no intermediate Vec<&str> allocation.

Unlike Self::sql_values_joined (which emits SQL literals: quoted strings / integer values), this emits the human-readable variant names for diagnostics such as “allowed values are: a, b, c”. For an integer enum the member names are used.

use vespertide_core::{EnumValues, NumValue};

let s = EnumValues::String(vec!["active".into(), "inactive".into()]);
assert_eq!(s.variant_names_joined(", "), "active, inactive");

let i = EnumValues::Integer(vec![
    NumValue { name: "low".into(),  value: 0  },
    NumValue { name: "high".into(), value: 10 },
]);
assert_eq!(i.variant_names_joined(", "), "low, high");

let empty = EnumValues::String(vec![]);
assert_eq!(empty.variant_names_joined(", "), "");
Source

pub fn len(&self) -> usize

Get the number of variants

Source

pub fn is_empty(&self) -> bool

Check if there are no variants

Source

pub fn contains_value(&self, value: &str) -> bool

Returns true when value matches any variant of this enum.

For string enums the comparison is exact-string against each variant. For integer enums the value is first parsed as i64 (matching the NumValue::value storage type): successful parses match against NumValue::value, failed parses fall back to matching against NumValue::name. Mirrors the loose JSON-default behaviour expected by the planner validator so a model author can write either the numeric literal (5) or the variant name ("Active") for an integer enum default.

Source

pub fn sql_values_joined(&self, separator: &str) -> String

Format every variant for CREATE TYPE … AS ENUM(...) / CHECK (col IN (...)) and join with separator, writing into one buffer — no intermediate Vec<String> allocation.

Mirrors vespertide_query::sql::helpers::quote_idents and vespertide_core::schema::names::join_column_names.

use vespertide_core::{EnumValues, NumValue};

let s = EnumValues::String(vec!["active".into(), "O'Brien".into()]);
assert_eq!(s.sql_values_joined(", "), "'active', 'O''Brien'");

let i = EnumValues::Integer(vec![
    NumValue { name: "low".into(),  value: 0  },
    NumValue { name: "high".into(), value: 10 },
]);
assert_eq!(i.sql_values_joined(", "), "0, 10");

let empty = EnumValues::String(vec![]);
assert_eq!(empty.sql_values_joined(", "), "");

Trait Implementations§

Source§

impl Clone for EnumValues

Source§

fn clone(&self) -> Self

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 EnumValues

Source§

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

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

impl<'de> Deserialize<'de> for EnumValues

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for EnumValues

Source§

impl From<Vec<&str>> for EnumValues

Source§

fn from(values: Vec<&str>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<String>> for EnumValues

Source§

fn from(values: Vec<String>) -> Self

Converts to this type from the input type.
Source§

impl JsonSchema for EnumValues

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for EnumValues

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for EnumValues

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for EnumValues

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

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

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