Assignments

Struct Assignments 

pub struct Assignments { /* private fields */ }
Expand description

An ordered map of field assignments for an Update statement.

Each entry maps a field projection (identifying which field to change) to an Assignment (how to change it). The entries are ordered by projection, allowing range queries over prefixes.

§Examples

use toasty_core::stmt::{Assignments, Expr, Projection};

let mut assignments = Assignments::default();
assert!(assignments.is_empty());

assignments.set(Projection::single(0), Expr::null());
assert_eq!(assignments.len(), 1);

Implementations§

§

impl Assignments

pub fn new() -> Assignments

Creates an empty Assignments.

pub fn is_empty(&self) -> bool

Returns true if there are no assignments.

pub fn len(&self) -> usize

Returns the number of assigned projections (keys).

pub fn contains<Q>(&self, key: &Q) -> bool
where Q: AsRef<[usize]> + ?Sized,

Returns true if an assignment exists for the given projection.

The key accepts any type that implements AsRef<[usize]>:

  • Projection — look up by projection directly
  • &[usize] — a slice of field indices (e.g., &[1, 2])
  • [usize; N] — a fixed-size array (e.g., [1], [1, 2]). Integer literals infer as usize from the AsRef<[usize]> bound, so &[1] works without a suffix.

pub fn get<Q>(&self, key: &Q) -> Option<&Assignment>
where Q: AsRef<[usize]> + ?Sized,

Returns a reference to the assignment for the given projection, if any.

The key accepts any type that implements AsRef<[usize]>:

  • Projection — look up by projection directly
  • &[usize] — a slice of field indices (e.g., &[1, 2])
  • [usize; N] — a fixed-size array (e.g., [1], [1, 2]). Integer literals infer as usize from the AsRef<[usize]> bound, so &[1] works without a suffix.

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Assignment>
where Q: AsRef<[usize]> + ?Sized,

Returns a mutable reference to the assignment for the given projection.

The key accepts any type that implements AsRef<[usize]>:

  • Projection — look up by projection directly
  • &[usize] — a slice of field indices (e.g., &[1, 2])
  • [usize; N] — a fixed-size array (e.g., [1], [1, 2]). Integer literals infer as usize from the AsRef<[usize]> bound, so &[1] works without a suffix.

pub fn set<Q>(&mut self, key: Q, expr: impl Into<Expr>)
where Q: Into<Projection>,

Sets a field to the given expression value, replacing any existing assignment for that projection.

pub fn unset<Q>(&mut self, key: &Q)
where Q: AsRef<[usize]> + ?Sized,

Removes the assignment for the given projection, if any.

The key accepts any type that implements AsRef<[usize]>:

  • Projection — look up by projection directly
  • &[usize] — a slice of field indices (e.g., &[1, 2])
  • [usize; N] — a fixed-size array (e.g., [1], [1, 2]). Integer literals infer as usize from the AsRef<[usize]> bound, so &[1] works without a suffix.

pub fn insert<Q>(&mut self, key: Q, expr: impl Into<Expr>)
where Q: Into<Projection>,

Insert a value into a set. The expression should evaluate to a single value that is inserted into the set.

pub fn remove<Q>(&mut self, key: Q, expr: impl Into<Expr>)
where Q: Into<Projection>,

Adds a Remove assignment for the given projection.

pub fn take<Q>(&mut self, key: &Q) -> Option<Assignment>
where Q: AsRef<[usize]> + ?Sized,

Removes and returns the assignment for the given projection.

The key accepts any type that implements AsRef<[usize]>:

  • Projection — look up by projection directly
  • &[usize] — a slice of field indices (e.g., &[1, 2])
  • [usize; N] — a fixed-size array (e.g., [1], [1, 2]). Integer literals infer as usize from the AsRef<[usize]> bound, so &[1] works without a suffix.

pub fn keys(&self) -> impl Iterator<Item = &Projection>

Returns an iterator over the assignment projections (keys).

pub fn iter(&self) -> impl Iterator<Item = (&Projection, &Assignment)>

Returns an iterator over (projection, assignment) pairs.

pub fn iter_mut( &mut self, ) -> impl Iterator<Item = (&Projection, &mut Assignment)>

Returns a mutable iterator over (projection, assignment) pairs.

Trait Implementations§

§

impl Clone for Assignments

§

fn clone(&self) -> Assignments

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Assignments

§

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

Formats the value using the given formatter. Read more
§

impl Default for Assignments

§

fn default() -> Assignments

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

impl<Q> Index<Q> for Assignments
where Q: AsRef<[usize]>,

Indexes into the assignments by projection. Panics if no assignment exists for the given key.

The index accepts any type that implements AsRef<[usize]>: Projection, &[usize], or [usize; N] arrays.

§

type Output = Assignment

The returned type after indexing.
§

fn index(&self, index: Q) -> &<Assignments as Index<Q>>::Output

Performs the indexing (container[index]) operation. Read more
§

impl<Q> IndexMut<Q> for Assignments
where Q: AsRef<[usize]>,

Mutably indexes into the assignments by projection. Panics if no assignment exists for the given key.

The index accepts any type that implements AsRef<[usize]>: Projection, &[usize], or [usize; N] arrays.

§

fn index_mut(&mut self, index: Q) -> &mut <Assignments as Index<Q>>::Output

Performs the mutable indexing (container[index]) operation. Read more
§

impl<'a> IntoIterator for &'a Assignments

§

type Item = (&'a Projection, &'a Assignment)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Projection, Assignment>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <&'a Assignments as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl IntoIterator for Assignments

§

type Item = (Projection, Assignment)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<Projection, Assignment>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <Assignments as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl PartialEq for Assignments

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.
§

impl StructuralPartialEq for Assignments

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