Skip to main content

PreferenceValue

Enum PreferenceValue 

Source
#[non_exhaustive]
pub enum PreferenceValue {
#[non_exhaustive]
Timezone { value: String, },
#[non_exhaustive]
DateGrain { grain: DateGrain, },
#[non_exhaustive]
OutputStyle { style: OutputStyle, },
#[non_exhaustive]
DefaultProfile { name: String, }, }
Expand description

A bounded user preference. Closed enums and shape-validated strings only; no free-text variant exists by design.

Deserialize is hand-rolled, not derived: the string-carrying variants run their shape validators on deserialization too, so a {"kind":"timezone", "value":"SELECT ..."} row is refused by the type, not only by the store’s admission gate. A derived Deserialize would populate the field directly and bypass the constructors — exactly the “validated constructor beside a publicly-constructible variant” the security standard warns about, and the spec’s “make it unrepresentable, not filtered” rule.

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

#[non_exhaustive]
Timezone

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§value: String
§

#[non_exhaustive]
DateGrain

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§

#[non_exhaustive]
OutputStyle

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§

#[non_exhaustive]
DefaultProfile

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§name: String

Implementations§

Source§

impl PreferenceValue

Source

pub fn kind(&self) -> &'static str

The stable discriminator persisted as preference_kind, and used as part of the store’s primary key.

Source

pub fn required_scope(&self) -> ScopeRequirement

The scope this value must be stored under. A value set at the wrong scope is a typed error, never a silent coercion.

Source

pub fn matches_scope(&self, scope: &PreferenceScope) -> bool

True if scope is the one this value requires. Convenience over required_scope().matches(scope).

Source

pub fn timezone(value: impl AsRef<str>) -> Result<Self, ContractError>

Construct a timezone preference. Validation is shape only: non-empty, ≤64 chars, ASCII alphanumeric plus /, _, + and -. A wrong-but- well-shaped timezone is a user error they can see and fix; bundling an IANA list to validate membership would be a maintenance burden that goes stale. A fictional-but-well-shaped name is accepted on purpose.

Source

pub fn date_grain(grain: DateGrain) -> Self

Source

pub fn output_style(style: OutputStyle) -> Self

Source

pub fn default_profile(name: impl AsRef<str>) -> Result<Self, ContractError>

Construct a default-profile preference from a profile name. The name is validated by the same shape rules as a database object name: non-empty, bounded, no control characters. A name is not an identity — it never reaches the database bytes as p-…, and it is resolved against the live connections.toml at use time, not stored as a pointer to a profile.

Source

pub fn timezone_value(&self) -> Option<&str>

The persisted string for a Timezone value, or None for other kinds. Used only by tests that assert a round-tripped value byte-for-byte.

Source

pub fn default_profile_name(&self) -> Option<&str>

The persisted name for a DefaultProfile value, or None for other kinds.

Trait Implementations§

Source§

impl Clone for PreferenceValue

Source§

fn clone(&self) -> PreferenceValue

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 PreferenceValue

Source§

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

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

impl<'de> Deserialize<'de> for PreferenceValue

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 PreferenceValue

Source§

impl PartialEq for PreferenceValue

Source§

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

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 PreferenceValue

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