Skip to main content

Projection

Struct Projection 

Source
pub struct Projection<'a, TD> { /* private fields */ }
Expand description

Projection expression builder that automatically includes the table’s key attributes.

Projection<'a, TD> builds a DynamoDB ProjectionExpression that limits which attributes are returned by a Get or Query/Scan operation. It always includes the table’s partition key (and sort key for composite-key tables) so that the resulting Item<TD> upholds its invariant of always containing the key attributes.

Attribute names that are DynamoDB reserved words are automatically escaped with # expression attribute name placeholders.

§Examples

Projecting a subset of user attributes:

use dynamodb_facade::Projection;

// Request only "name" and "email" — PK and SK are added automatically.
let proj = Projection::<PlatformTable>::new(["name", "email"]);

// The rendered expression includes PK, SK, and the requested fields.
let rendered = format!("{proj}");
assert_eq!(format!("{proj}"), "PK,SK,email,name");
let rendered_with_placeholders = format!("{proj:#}");
assert!(rendered_with_placeholders.contains("#p0 = name"));

Implementations§

Source§

impl<'a, TD: TableDefinition> Projection<'a, TD>
where Self: KeySchemaProjection<'a, TD::KeySchema, <TD::KeySchema as KeySchema>::Kind>,

Source

pub fn new(attrs: impl IntoIterator<Item = impl Into<Cow<'a, str>>>) -> Self

Creates a projection from an iterator of attribute names.

The table’s key attributes (PK, and SK for composite-key tables) are always prepended to the provided list, ensuring the resulting Item<TD> is always valid for the table schema.

Duplicate attribute names are deduplicated automatically.

§Examples
use dynamodb_facade::Projection;

// Project "name" and "email"; PK + SK are added automatically.
let proj = Projection::<PlatformTable>::new(["name", "email"]);

let rendered = format!("{proj}");
assert!(rendered.contains("PK"));
assert!(rendered.contains("SK"));
assert!(rendered.contains("name"));
assert!(rendered.contains("email"));
let rendered_with_placeholders = format!("{proj:#}");
assert!(rendered_with_placeholders.contains("#p0 = name"));
Source

pub fn keys_only() -> Self

Creates a projection that contains only the table’s key attributes.

The result is a projection that includes exactly PK (for simple-key tables) or PK + SK (for composite-key tables).

This is useful when you want to list or scan matching items without fetching any payload data — for example, collecting the keys of all enrollments for a user before issuing a batch delete.

§Examples
use dynamodb_facade::Projection;

// PlatformTable has composite key PK + SK — those are the only attributes returned.
let proj = Projection::<PlatformTable>::keys_only();

let rendered = format!("{proj}");
assert_eq!(rendered, "PK,SK");

Trait Implementations§

Source§

impl<'a, TD: Clone> Clone for Projection<'a, TD>

Source§

fn clone(&self) -> Projection<'a, TD>

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

impl<'a, TD: Debug> Debug for Projection<'a, TD>

Source§

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

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

impl<TD> Display for Projection<'_, TD>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, TD> Freeze for Projection<'a, TD>

§

impl<'a, TD> RefUnwindSafe for Projection<'a, TD>
where TD: RefUnwindSafe,

§

impl<'a, TD> Send for Projection<'a, TD>
where TD: Send,

§

impl<'a, TD> Sync for Projection<'a, TD>
where TD: Sync,

§

impl<'a, TD> Unpin for Projection<'a, TD>
where TD: Unpin,

§

impl<'a, TD> UnsafeUnpin for Projection<'a, TD>

§

impl<'a, TD> UnwindSafe for Projection<'a, TD>
where TD: 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> 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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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