Skip to main content

Var

Struct Var 

Source
pub struct Var { /* private fields */ }
Expand description

A managed environment variable.

Var carries only metadata. The actual value is stored separately:

§Examples

use evault_core::model::{Var, Group, VarKind};

let v = Var::new("DATABASE_URL", Group::User, VarKind::Secret);
assert_eq!(v.name(), "DATABASE_URL");
assert_eq!(v.kind(), VarKind::Secret);

Implementations§

Source§

impl Var

Source

pub fn new(name: impl Into<String>, group: Group, kind: VarKind) -> Self

Create a new Var from already-validated input.

This constructor does not call Self::validate_name; it is intended for tests and code paths that have already validated the name upstream. Never call this directly with user-supplied input: use Self::try_new instead.

Source

pub fn try_new( name: impl Into<String>, group: Group, kind: VarKind, ) -> Result<Self, MetadataError>

Create a new Var from possibly-untrusted input, validating the name through Self::validate_name.

This is the constructor that CLI/TUI surfaces and any other path that accepts user input should use.

§Errors

Returns MetadataError::Invalid if name does not satisfy Self::validate_name.

§Examples
use evault_core::model::{Var, Group, VarKind};

assert!(Var::try_new("DATABASE_URL", Group::User, VarKind::Plain).is_ok());
assert!(Var::try_new("1BAD", Group::User, VarKind::Plain).is_err());
Source

pub const fn from_trusted_parts( id: VarId, name: String, group: Group, kind: VarKind, tags: Vec<String>, length: usize, created_at: OffsetDateTime, updated_at: OffsetDateTime, ) -> Self

Reconstruct a Var from already-stored fields without re-validating.

This bypasses Self::validate_name. Reach for it only from a code path where the data has demonstrably been validated upstream — e.g. tests or in-process serialization. Backends that rehydrate from external storage (SQLite, files, …) must call Self::try_from_parts instead so that a corrupted or tampered row cannot inject malformed names into the rest of the system.

Source

pub fn try_from_parts( id: VarId, name: String, group: Group, kind: VarKind, tags: Vec<String>, length: usize, created_at: OffsetDateTime, updated_at: OffsetDateTime, ) -> Result<Self, MetadataError>

Reconstruct a Var from already-stored fields, re-validating the name through Self::validate_name.

This is the entry point that storage backends (SQLCipher, in-memory, …) should use when rehydrating rows: it ensures a tampered or corrupted database cannot smuggle in a malformed variable name.

§Errors

Returns MetadataError::Invalid if name does not satisfy Self::validate_name.

Source

pub fn validate_name(candidate: &str) -> Result<&str, MetadataError>

Validate that candidate is acceptable as a variable name.

Accepted names follow the conventional environment-variable shape:

  • non-empty
  • 64 characters or fewer
  • first character is an ASCII letter or underscore
  • subsequent characters are ASCII alphanumerics or underscores
§Errors

Returns MetadataError::Invalid if any rule is violated.

§Examples
use evault_core::model::Var;
assert!(Var::validate_name("DATABASE_URL").is_ok());
assert!(Var::validate_name("").is_err());
assert!(Var::validate_name("1BAD").is_err());
Source

pub const fn id(&self) -> VarId

Returns the variable’s stable identifier.

Source

pub fn name(&self) -> &str

Returns the variable’s name.

Source

pub const fn group(&self) -> &Group

Returns the variable’s group.

Source

pub const fn kind(&self) -> VarKind

Returns the variable’s storage kind.

Source

pub fn tags(&self) -> &[String]

Returns the tag list.

Source

pub fn set_tags(&mut self, tags: Vec<String>)

Replaces the tag list.

Tags are not deduplicated nor sorted; callers should apply their own normalization where it matters.

Source

pub const fn length(&self) -> usize

Returns the length of the value (without revealing it).

The length is captured at write-time by the registry and is intended for display only.

Source

pub fn set_length(&mut self, length: usize)

Sets the recorded value length and bumps updated_at.

Source

pub const fn created_at(&self) -> OffsetDateTime

Returns when the variable was created (UTC).

Source

pub const fn updated_at(&self) -> OffsetDateTime

Returns when the variable was last modified (UTC).

Trait Implementations§

Source§

impl Clone for Var

Source§

fn clone(&self) -> Var

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 Var

Source§

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

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

impl<'de> Deserialize<'de> for Var

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 PartialEq for Var

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 Serialize for Var

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 Eq for Var

Source§

impl StructuralPartialEq for Var

Auto Trait Implementations§

§

impl Freeze for Var

§

impl RefUnwindSafe for Var

§

impl Send for Var

§

impl Sync for Var

§

impl Unpin for Var

§

impl UnsafeUnpin for Var

§

impl UnwindSafe for Var

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