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

Represents a DynamoDB document path. For example, foo[3][7].bar[2].baz.

When used in an Expression, attribute names in a Path are automatically handled as expression attribute names, allowing for names that would not otherwise be permitted by DynamoDB. For example, foo[3][7].bar[2].baz would become something similar to #0[3][7].#1[2].#2, and the names would be in the expression_attribute_names.

See also: Element, Name, IndexedField

Examples

The safest way to construct a Path is to parse it.

use dynamodb_expression::path::Path;

let path: Path = "foo".parse().unwrap();
let path: Path = "foo[3]".parse().unwrap();
let path: Path = "foo[3][7]".parse().unwrap();
let path: Path = "foo[3][7].bar".parse().unwrap();
let path: Path = "bar.baz".parse().unwrap();
let path: Path = "baz[0].foo".parse().unwrap();

This makes the common assumption that each path element is separated by a period (.). For example, the path foo.bar gets treated as if foo is a top-level attribute, and bar is a sub-attribute of foo. However, . is also a valid character in an attribute name.

If you have an attribute name with a . in it, and need it to not be treated as a separator, you can construct the Path a few different ways. Here are some ways you can correctly construct a Path using attr.name as the problematic attribute name.

use dynamodb_expression::path::{Element, Path};

// As a top-level attribute name:
let path = Path::name("attr.name");

// If the top-level attribute, `foo`, has a sub-attribute named `attr.name`:
let path = Path::from_iter([
    Element::name("foo"),
    Element::name("attr.name"),
]);

// If top-level attribute `foo`, item 3 (i.e., `foo[3]`) has a sub-attribute
// named `attr.name`:
let path = Path::from_iter([
    Element::indexed_field("foo", 3),
    Element::name("attr.name"),
]);

// If top-level attribute `foo`, item 3, sub-item 7 (i.e., `foo[3][7]`) has
// an attribute named `attr.name`:
let path = Path::from_iter([
    Element::indexed_field("foo", [3, 7]),
    Element::name("attr.name"),
]);

Each of these are ways to create a Path instance for foo[3][7].bar[2].baz.

use dynamodb_expression::{path::{Element, Path}};

// A `Path` can be parsed from a string
let path: Path = "foo[3][7].bar[2].baz".parse().unwrap();

// `Path` implements `FromIterator` for items that are `Element`s.
let path = Path::from_iter([
    Element::indexed_field("foo", [3, 7]),
    Element::indexed_field("bar", 2),
    Element::name("baz"),
]);

// Of course, that means you can `.collect()` into a `Path`.
let path: Path = [
    Element::indexed_field("foo", [3, 7]),
    Element::indexed_field("bar", 2),
    Element::name("baz"),
]
.into_iter()
.collect();

// `Element` can be converted into from string/index tuples. Where the
// string is the attribute name. In this case, an "index" is an array,
// slice, `Vec` of, or a single `usize`.
//
// It's smart about it, though. If if there's one or zero indexes it'll do
// the right thing. This helps when you're chaining iterator adapters and
// the results are values with inconsistent numbers of indexes.
let path = Path::from_iter(
    [
        ("foo", vec![3, 7]),
        ("bar", vec![2]),
        ("baz", vec![]),
    ]
    .map(Element::from),
);


// `Path` implements `FromIterator` for items that are `Into<Element>`.
// So, the above example can be simplified.
let path = Path::from_iter([
    ("foo", vec![3, 7]),
    ("bar", vec![2]),
    ("baz", vec![]),
]);

If you have a document path where an attribute name includes a period (.), you will need to explicitly create the Elements for that Path.

// If the attribute name is `foo.bar`:
let path = Path::from(Element::name("foo.bar"));

// If the item at `foo[3]` has an attribute named `bar.baz`:
let path = Path::from_iter([
    Element::indexed_field("foo", 3),
    Element::name("bar.baz")
]);

A Name can be converted into a Path.

use dynamodb_expression::path::{Element, Name, Path};

let name = Name::from("foo");
let path = Path::from(name);
assert_eq!(Path::from(Element::name("foo")), path);

Implementations§

source§

impl Path

source

pub fn name<T>(name: T) -> Selfwhere T: Into<Name>,

Constructs a Path for a single attribute name (with no indexes or sub-attributes). If you have a attribute name with one or more indexes, use Path::indexed_field().

source

pub fn indexed_field<N, I>(name: N, indexes: I) -> Selfwhere N: Into<Name>, I: Indexes,

Constructs a Path for a single attribute name (with no indexes or sub-attributes). If you have a attribute name with no indexes, you can pass an empty collection, or use Path::name.

indexes here can be an array, slice, Vec of, or single usize.

assert_eq!("foo[3]", Path::indexed_field("foo", 3).to_string());
assert_eq!("foo[3]", Path::indexed_field("foo", [3]).to_string());
assert_eq!("foo[3]", Path::indexed_field("foo", &[3]).to_string());
assert_eq!("foo[3]", Path::indexed_field("foo", vec![3]).to_string());

assert_eq!("foo[7][4]", Path::indexed_field("foo", [7, 4]).to_string());
assert_eq!("foo[7][4]", Path::indexed_field("foo", &[7, 4]).to_string());
assert_eq!("foo[7][4]", Path::indexed_field("foo", vec![7, 4]).to_string());

assert_eq!("foo", Path::indexed_field("foo", []).to_string());
assert_eq!("foo", Path::indexed_field("foo", &[]).to_string());
assert_eq!("foo", Path::indexed_field("foo", vec![]).to_string());

See also: IndexedField, Element::indexed_field

source

pub fn append(&mut self, other: Path)

Appends another Path to the end of this one.

use dynamodb_expression::path::Path;

let mut path: Path = "foo[2]".parse().unwrap();
let sub_path: Path = "bar".parse().unwrap();
path.append(sub_path);
assert_eq!("foo[2].bar".parse::<Path>().unwrap(), path);
source§

impl Path

Methods relating to building condition and filter expressions.

source

pub fn equal<T>(self, right: T) -> Conditionwhere T: Into<Operand>,

Check if the value at this Path is equal to the given value.

DynamoDB documentation.

source

pub fn not_equal<T>(self, right: T) -> Conditionwhere T: Into<Operand>,

Check if the value at this Path is not equal to the given value.

DynamoDB documentation.

source

pub fn greater_than<T>(self, right: T) -> Conditionwhere T: Into<Operand>,

Check if the value at this Path is greater than the given value.

DynamoDB documentation.

source

pub fn greater_than_or_equal<T>(self, right: T) -> Conditionwhere T: Into<Operand>,

Check if the value at this Path is greater than or equal to the given value.

DynamoDB documentation.

source

pub fn less_than<T>(self, right: T) -> Conditionwhere T: Into<Operand>,

Check if the value at this Path is less than the given value.

DynamoDB documentation.

source

pub fn less_than_or_equal<T>(self, right: T) -> Conditionwhere T: Into<Operand>,

Check if the value at this Path is less than or equal to the given value.

DynamoDB documentation.

source

pub fn between<L, U>(self, lower: L, upper: U) -> Conditionwhere L: Into<Operand>, U: Into<Operand>,

self BETWEEN b AND c - true if self is greater than or equal to b, and less than or equal to c.

DynamoDB documentation.

source

pub fn in_<I, T>(self, items: I) -> Conditionwhere I: IntoIterator<Item = T>, T: Into<Operand>,

self IN (b[, ..]) — true if self is equal to any value in the list.

The list can contain up to 100 values. It must have at least 1.

DynamoDB documentation.

source

pub fn attribute_exists(self) -> Condition

True if the item contains the attribute specified by Path.

DynamoDB documentation.

source

pub fn attribute_not_exists(self) -> Condition

True if the attribute specified by Path does not exist in the item.

DynamoDB documentation.

source

pub fn attribute_type(self, attribute_type: Type) -> Condition

True if the attribute at the specified Path is of a particular data type.

DynamoDB documentation.

source

pub fn begins_with<T>(self, prefix: T) -> Conditionwhere T: Into<StringOrRef>,

True if the attribute specified by Path begins with a particular substring.

DynamoDB documentation.

source

pub fn contains<V>(self, operand: V) -> Conditionwhere V: Into<Scalar>,

True if the attribute specified by Path is one of the following:

  • A String that contains a particular substring.
  • A Set that contains a particular element within the set.
  • A List that contains a particular element within the list.

The operand must be a String if the attribute specified by path is a String. If the attribute specified by path is a Set, the operand must be the set’s element type.

DynamoDB documentation.

source

pub fn size(self) -> Size

Returns a number representing an attribute’s size.

DynamoDB documentation.

source§

impl Path

Methods relating to building update expressions.

source

pub fn assign<T>(self, value: T) -> Assignwhere T: Into<Value>,

See Assign

source

pub fn math(self) -> MathBuilder

Sets this as the destination in a Math builder.

source

pub fn list_append(self) -> ListAppendBuilder

Sets this as the destination in a ListAppend builder.

source

pub fn if_not_exists(self) -> IfNotExistsBuilder

Sets this as the destination in an IfNotExists builder.

source

pub fn delete<T>(self, set: T) -> Deletewhere T: Into<Set>,

See Delete

source

pub fn add<T>(self, value: T) -> Addwhere T: Into<AddValue>,

See Add

source

pub fn remove(self) -> Remove

See Remove

source§

impl Path

source

pub fn key(self) -> Key

Turns this Path into a Key, for building a key condition expression.

Trait Implementations§

source§

impl Clone for Path

source§

fn clone(&self) -> Path

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Path

source§

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

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

impl Display for Path

source§

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

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

impl From<Path> for String

source§

fn from(path: Path) -> Self

Converts to this type from the input type.
source§

impl From<Path> for Vec<Element>

source§

fn from(path: Path) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Pathwhere T: Into<Element>,

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl<T> FromIterator<T> for Pathwhere T: Into<Element>,

source§

fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
source§

impl FromStr for Path

§

type Err = PathParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for Path

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Path

source§

fn cmp(&self, other: &Path) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Path

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Path

source§

fn partial_cmp(&self, other: &Path) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<Path> for Name

source§

fn try_from(path: Path) -> Result<Self, Self::Error>

A Path consisting of a single, unindexed attribute can be converted into a Name.

use dynamodb_expression::path::{Element, Name, Path};

let path: Path = "foo".parse().unwrap();
let name = Name::try_from(path).unwrap();
assert_eq!(Name::from("foo"), name);

If the Path has indexes, or has sub-attributes, it cannot be converted, and the original Path is returned.

let path: Path = "foo[0]".parse().unwrap();
let err = Name::try_from(path.clone()).unwrap_err();
assert_eq!(path, err);

let path: Path = "foo.bar".parse().unwrap();
let err = Name::try_from(path.clone()).unwrap_err();
assert_eq!(path, err);
§

type Error = Path

The type returned in the event of a conversion error.
source§

impl Eq for Path

source§

impl StructuralEq for Path

source§

impl StructuralPartialEq for Path

Auto Trait Implementations§

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnwindSafe for Path

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Comparable<K> for Qwhere Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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

§

impl<Unshared, Shared> IntoShared<Shared> for Unsharedwhere Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more