Skip to main content

Field

Struct Field 

Source
pub struct Field<T, V> { /* private fields */ }
Expand description

Field accessor.

Carries both the column / serde-key name (used by downstream SQL-emitting consumers like djogi) and the in-memory extractor used by sassi’s predicate evaluator. The two halves let the same Field<T, V> value participate in a SQL WHERE emit on a backend AND a Rust-side evaluate() walk on a frontend, without diverging.

Internal storage is pub(crate) to keep the (name, extractor) pair stable post-construction. Use Field::name and Field::extract accessors instead of direct field access.

§Example

use sassi::Field;

struct User { id: i64, age: u32 }

// Normally generated by `#[derive(Cacheable)]`; shown here for
// documentation:
let age_field: Field<User, u32> = Field::new("age", |u| &u.age);
let alice = User { id: 1, age: 30 };
assert_eq!(*age_field.extract(&alice), 30);
assert_eq!(age_field.name(), "age");

Implementations§

Source§

impl<T, V> Field<T, V>

Source

pub const fn new(name: &'static str, extract: fn(&T) -> &V) -> Self

Construct a new Field<T, V>. Normally invoked via the generated T::fields() constructor; available here for hand impls.

Source

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

Column / serde-key name. Stable post-construction.

Source

pub fn extract<'a>(&self, value: &'a T) -> &'a V

Apply the extractor to a value. Stable post-construction — the extractor cannot be reassigned, only invoked.

Source§

impl<T: 'static, V: PartialEq + Send + Sync + 'static> Field<T, V>

Source

pub fn eq(&self, val: V) -> BasicPredicate<T>

field == value.

Source

pub fn neq(&self, val: V) -> BasicPredicate<T>

field != value.

Source§

impl<T: 'static, V: PartialOrd + Send + Sync + 'static> Field<T, V>

Source

pub fn gt(&self, val: V) -> BasicPredicate<T>

field > value.

Source

pub fn gte(&self, val: V) -> BasicPredicate<T>

field >= value.

Source

pub fn lt(&self, val: V) -> BasicPredicate<T>

field < value.

Source

pub fn lte(&self, val: V) -> BasicPredicate<T>

field <= value.

Source

pub fn between(&self, low: V, high: V) -> BasicPredicate<T>

low <= field <= high (inclusive on both ends).

Operand value layout: Arc<(V, V)> carrying (low, high).

Source§

impl<T: 'static, V: PartialEq + Send + Sync + 'static> Field<T, V>

Source

pub fn in_(&self, vals: Vec<V>) -> BasicPredicate<T>

field IN (values…). Operand value layout: Arc<Vec<V>>.

Source

pub fn not_in(&self, vals: Vec<V>) -> BasicPredicate<T>

field NOT IN (values…). Operand value layout: Arc<Vec<V>>.

Source§

impl<T: 'static, U: Send + Sync + 'static> Field<T, Option<U>>

Source

pub fn is_null(&self) -> BasicPredicate<T>

field IS NULL. Only meaningful on Option<U> fields. Operand value layout: Arc<()> (no operand).

Source

pub fn is_not_null(&self) -> BasicPredicate<T>

field IS NOT NULL. Only meaningful on Option<U> fields. Operand value layout: Arc<()> (no operand).

Source§

impl<T, V> Field<T, Option<V>>

Source

pub fn some(&self) -> PresentField<T, V>

Compare only the present Some(V) value.

Source§

impl<T: 'static> Field<T, String>

Source

pub fn contains(&self, needle: &str) -> BasicPredicate<T>

Case-sensitive substring match: field contains the needle. Operand value layout: Arc<String>.

Source

pub fn icontains(&self, needle: &str) -> BasicPredicate<T>

Case-insensitive substring match using ASCII-only folding. Operand value layout: Arc<String> — original (non-lowered) needle for inspection.

Source

pub fn starts_with(&self, prefix: &str) -> BasicPredicate<T>

field starts with the prefix (case-sensitive). Operand value layout: Arc<String>.

Source

pub fn istarts_with(&self, prefix: &str) -> BasicPredicate<T>

field starts with the prefix (case-insensitive). Operand value layout: Arc<String> — original (non-lowered).

Source

pub fn ends_with(&self, suffix: &str) -> BasicPredicate<T>

field ends with the suffix (case-sensitive). Operand value layout: Arc<String>.

Source

pub fn iends_with(&self, suffix: &str) -> BasicPredicate<T>

field ends with the suffix (case-insensitive). Operand value layout: Arc<String> — original (non-lowered).

Source

pub fn iexact(&self, val: &str) -> BasicPredicate<T>

field == value using ASCII-only case folding. Operand value layout: Arc<String> — original.

Trait Implementations§

Source§

impl<T, V> Clone for Field<T, V>

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<T, V> Debug for Field<T, V>

Source§

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

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

impl<T: 'static, V: 'static> Default for Field<T, V>

Source§

fn default() -> Self

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

impl<T, V> Copy for Field<T, V>

Auto Trait Implementations§

§

impl<T, V> Freeze for Field<T, V>

§

impl<T, V> RefUnwindSafe for Field<T, V>

§

impl<T, V> Send for Field<T, V>
where T: Send, V: Send,

§

impl<T, V> Sync for Field<T, V>
where T: Sync, V: Sync,

§

impl<T, V> Unpin for Field<T, V>
where T: Unpin, V: Unpin,

§

impl<T, V> UnsafeUnpin for Field<T, V>

§

impl<T, V> UnwindSafe for Field<T, V>
where T: UnwindSafe, V: UnwindSafe,

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> 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 = 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> 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