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>
impl<'a, TD: TableDefinition> Projection<'a, TD>
Sourcepub fn new(attrs: impl IntoIterator<Item = impl Into<Cow<'a, str>>>) -> Self
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"));Sourcepub fn keys_only() -> Self
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>
impl<'a, TD: Clone> Clone for Projection<'a, TD>
Source§fn clone(&self) -> Projection<'a, TD>
fn clone(&self) -> Projection<'a, TD>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a, TD: Debug> Debug for Projection<'a, TD>
impl<'a, TD: Debug> Debug for Projection<'a, TD>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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