Skip to main content

Record

Struct Record 

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

A dynamic record: an entity name, an optional id, and its attributes.

Implementations§

Source§

impl Record

Source

pub fn new(entity: impl Into<String>) -> Self

An empty record for entity, with no id (the shape of a create).

Source

pub fn with_id(entity: impl Into<String>, id: i64) -> Self

An empty record for an existing row (the shape of an update).

Source

pub fn entity(&self) -> &str

The entity this record belongs to: a fixed table or a runtime content type.

Source

pub fn id(&self) -> Option<i64>

The primary key, None until a create returns one.

Source

pub fn set_id(&mut self, id: i64)

Records the id a create returned.

Source

pub fn set( &mut self, key: impl Into<String>, value: impl Into<AttrValue>, ) -> &mut Self

Sets an attribute, replacing any previous value. Chainable.

Source

pub fn get(&self, key: &str) -> Option<&AttrValue>

An attribute, or None when the key is absent. An attribute that is present and null returns Some(AttrValue::Null), which is a different thing: absent means “not part of this write”, null means “write NULL”.

Source

pub fn remove(&mut self, key: &str) -> Option<AttrValue>

Removes an attribute, returning it.

Source

pub fn contains(&self, key: &str) -> bool

Whether the key is present, null or not.

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &AttrValue)>

The attributes, in key order.

Source

pub fn len(&self) -> usize

How many attributes are set.

Source

pub fn is_empty(&self) -> bool

Whether no attribute is set.

Source

pub fn text(&self, key: &str) -> Option<&str>

The text at key, when it holds AttrValue::Text.

Source

pub fn int(&self, key: &str) -> Option<i64>

The integer at key.

Source

pub fn float(&self, key: &str) -> Option<f64>

The float at key.

Source

pub fn bool(&self, key: &str) -> Option<bool>

The boolean at key.

Source

pub fn datetime(&self, key: &str) -> Option<DateTime<Utc>>

The instant at key.

Source

pub fn json(&self, key: &str) -> Option<&Value>

The JSON at key.

Source

pub fn set_original(&mut self, previous: Record)

Records the row as it stood before this write, read inside the same transaction. The pipeline sets it on an update when the persister can supply one.

Source

pub fn has_original(&self) -> bool

Whether a pre-write snapshot is available. A create never has one, and neither does an update whose persister does not supply one.

Source

pub fn original(&self, key: &str) -> Option<&AttrValue>

The pre-write value at key.

Source

pub fn changed(&self, key: &str) -> bool

Whether this write changes key. Always false without a snapshot, so a change-based listener should check Record::has_original first rather than read “unchanged” into its absence.

The comparison is text-level today: a snapshot is read back as text, so a listener that re-types an unchanged value (a date parsed into a AttrValue::DateTime) reads as changed. Fine for stamping, not yet sufficient for a per-attribute diff.

Source

pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, Error>

Reads the attributes into a struct, for code that would rather work with types than a bag. Attributes the target does not name are ignored.

Source

pub fn from_text_map( entity: impl Into<String>, data: &HashMap<String, String>, ) -> Self

Builds a record from an all-text submission, the shape the form write path uses today. Every value arrives as AttrValue::Text, because a string carries no type; typed values come from field types and listeners.

Source

pub fn to_text_map(&self) -> HashMap<String, String>

The record as an all-text map, for a storage layer that binds strings. A null attribute becomes an empty string, matching that path’s existing “empty means none” contract.

Trait Implementations§

Source§

impl Clone for Record

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 Record

Source§

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

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

impl Default for Record

Source§

fn default() -> Self

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

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

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