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
impl EnumValues
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Check if this is an integer enum
Sourcepub fn variant_names_joined(&self, separator: &str) -> String
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(", "), "");Sourcepub fn contains_value(&self, value: &str) -> bool
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.
Sourcepub fn sql_values_joined(&self, separator: &str) -> String
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
impl Clone for EnumValues
Source§impl Debug for EnumValues
impl Debug for EnumValues
Source§impl<'de> Deserialize<'de> for EnumValues
impl<'de> Deserialize<'de> for EnumValues
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for EnumValues
Source§impl JsonSchema for EnumValues
impl JsonSchema for EnumValues
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for EnumValues
impl PartialEq for EnumValues
Source§impl Serialize for EnumValues
impl Serialize for EnumValues
impl StructuralPartialEq for EnumValues
Auto Trait Implementations§
impl Freeze for EnumValues
impl RefUnwindSafe for EnumValues
impl Send for EnumValues
impl Sync for EnumValues
impl Unpin for EnumValues
impl UnsafeUnpin for EnumValues
impl UnwindSafe for EnumValues
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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