Skip to main content

ScanRequest

Struct ScanRequest 

Source
pub struct ScanRequest<TD: TableDefinition, T = (), O: OutputFormat = Raw, F: FilterState = NoFilter, P: ProjectionState = NoProjection> { /* private fields */ }
Expand description

Builder for a DynamoDB Scan request.

Constructed via DynamoDBItemOp::scan / DynamoDBItemOp::scan_index (typed, with a concrete T) or ScanRequest::new / ScanRequest::new_index (stand-alone, raw output). The builder provides:

  • Output format — the result can be deserialized into T. Call .raw() to receive untyped Item<TD> values instead (one-way). Calling .project() also forces raw output.
  • Filter — call .filter() to add a server-side filter expression. DynamoDB accepts a single filter expression per request, so this can only be called once.
  • Projection — call .project() to limit which attributes are returned. This can only be called once.

Use .all() to collect all pages into a Vec, or .stream() for lazy page-by-page iteration.

Note: Scans read every item in the table (or index) and are significantly more expensive than queries. Prefer QueryRequest when possible.

§Errors

Returns Err if any DynamoDB page request fails or if deserialization of any returned item fails.

§Examples

use dynamodb_facade::{DynamoDBItemOp, Condition};

// Simple scan
let all_users /* : Vec<User> */ = User::scan(client).all().await?;

// Scan with a filter
let instructors /* : Vec<User> */ = User::scan(client)
    .filter(Condition::eq("role", "instructor"))
    .all()
    .await?;

Implementations§

Source§

impl<TD: TableDefinition> ScanRequest<TD>

Source

pub fn new(client: Client) -> Self

Creates a stand-alone ScanRequest against the full table with raw output.

Output is raw (T = (), O = Raw). For typed access, prefer DynamoDBItemOp::scan instead.

§Examples
use dynamodb_facade::ScanRequest;

let items = ScanRequest::<PlatformTable>::new(client).all().await?;
Source

pub fn new_index<I: IndexDefinition<TD>>(client: Client) -> Self

Creates a stand-alone ScanRequest scoped to a secondary index.

Output is raw (T = (), O = Raw). For typed access, prefer DynamoDBItemOp::scan_index instead.

§Examples
use dynamodb_facade::ScanRequest;

let items = ScanRequest::<PlatformTable>::new_index::<TypeIndex>(client)
    .all()
    .await?;
Source§

impl<TD: TableDefinition, T, O: OutputFormat, F: FilterState, P: ProjectionState> ScanRequest<TD, T, O, F, P>

Source

pub fn consistent_read(self) -> Self

Enables strongly consistent reads for this scan.

By default DynamoDB uses eventually consistent reads. Enabling consistent reads guarantees the most up-to-date data but consumes twice the read capacity units and is not supported on Global Secondary Indexes.

§Examples
use dynamodb_facade::DynamoDBItemOp;

let users /* : Vec<User> */ = User::scan(client).consistent_read().all().await?;
Source

pub fn limit(self, limit: i32) -> Self

Sets the maximum number of items to evaluate per page.

Note that DynamoDB evaluates up to limit items before applying any filter expression, so the number of items returned may be less than limit when a filter is active. Pagination continues automatically when using .all() or .stream().

§Examples
use dynamodb_facade::DynamoDBItemOp;

let users /* : Vec<User> */ = User::scan(client).limit(100).all().await?;
Source

pub fn into_inner(self) -> ScanFluentBuilder

Consumes the builder and returns the underlying SDK ScanFluentBuilder.

Use this escape hatch when you need to set options not exposed by this facade, or when integrating with code that expects the raw SDK builder.

§Examples
use dynamodb_facade::DynamoDBItemOp;

let sdk_builder = User::scan(client).into_inner();
// configure sdk_builder further, then call .send().await
Source§

impl<TD: TableDefinition, T, O: OutputFormat, P: ProjectionState> ScanRequest<TD, T, O, NoFilter, P>

Source

pub fn filter( self, filter: Condition<'_>, ) -> ScanRequest<TD, T, O, AlreadyHasFilter, P>

Adds a filter expression applied after items are read from the table.

DynamoDB accepts a single filter expression per request, so this method can only be called once. The filter is evaluated server-side after items are read but before they are returned, so it does not reduce read capacity consumption.

§Examples
use dynamodb_facade::{DynamoDBItemOp, Condition};

let instructors /* : Vec<User> */ = User::scan(client)
    .filter(Condition::eq("role", "instructor"))
    .all()
    .await?;
Source§

impl<TD: TableDefinition, T, O: OutputFormat, F: FilterState> ScanRequest<TD, T, O, F, NoProjection>

Source

pub fn project( self, projection: Projection<'_, TD>, ) -> ScanRequest<TD, T, Raw, F, AlreadyHasProjection>

Applies a projection expression, limiting the attributes returned per item.

This method can only be called once. It forces the output to raw Item<TD> because projected results may not contain all fields required for deserialization into T.

§Examples
use dynamodb_facade::{DynamoDBItemOp, Projection};

// Fetch only the "name" attribute for each user
let partial = User::scan(client)
    .project(Projection::new(["name"]))
    .all()
    .await?;
// partial: Vec<Item<PlatformTable>>
// with only "PK", "SK" and "name"
Source§

impl<TD: TableDefinition, T, F: FilterState, P: ProjectionState> ScanRequest<TD, T, Typed, F, P>

Source

pub fn raw(self) -> ScanRequest<TD, T, Raw, F, P>

Switches the output format from Typed to Raw.

After calling .raw(), .all() returns Vec<Item<TD>> and .stream() yields Result<Vec<Item<TD>>> (pages of raw items) instead of the typed equivalents. This transition is one-way.

§Examples
use dynamodb_facade::DynamoDBItemOp;

let raw_items = User::scan(client).raw().all().await?;
// raw_items: Vec<Item<PlatformTable>>
Source§

impl<TD: TableDefinition, T: DynamoDBItem<TD> + DeserializeOwned, F: FilterState, P: ProjectionState> ScanRequest<TD, T, Typed, F, P>

Source

pub async fn all(self) -> Result<Vec<T>>

Executes the scan, collecting all pages and returning items deserialized as T.

Automatically follows pagination tokens until all matching items have been retrieved. For large tables, prefer .stream() to avoid loading everything into memory at once.

§Errors

Returns Err if any DynamoDB page request fails or if deserialization of any item fails.

§Examples
use dynamodb_facade::DynamoDBItemOp;

let all_users /* : Vec<User> */ = User::scan(client).all().await?;
Source

pub fn stream(self) -> impl Stream<Item = Result<Vec<T>>>

Executes the scan as a lazy async stream, yielding one page at a time.

Each element yielded by the stream is a Vec<T> representing one page of results deserialized as T. Pages are fetched on demand as the stream is consumed. Use this for large tables where loading everything into memory at once is undesirable.

§Examples
use dynamodb_facade::DynamoDBItemOp;
use futures_util::StreamExt;
use std::pin::pin;

let stream = User::scan(client).stream();
// Must pin the stream
let mut stream = pin!(stream);

while let Some(result) = stream.next().await {
    let page /* : Vec<User> */ = result?;
    for user in page {
        let _ = user;
    }
}
Source§

impl<TD: TableDefinition, T, F: FilterState, P: ProjectionState> ScanRequest<TD, T, Raw, F, P>

Source

pub async fn all(self) -> Result<Vec<Item<TD>>>

Executes the scan, collecting all pages and returning raw item maps.

Automatically follows pagination tokens until all items have been retrieved.

§Errors

Returns Err if any DynamoDB page request fails.

§Examples
use dynamodb_facade::ScanRequest;

let items = ScanRequest::<PlatformTable>::new(client).all().await?;
// items: Vec<Item<PlatformTable>>
Source

pub fn stream(self) -> impl Stream<Item = Result<Vec<Item<TD>>>>

Executes the scan as a lazy async stream, yielding one page of raw item maps at a time.

Each element yielded by the stream is a Vec<Item<TD>> representing one page of results. Pages are fetched on demand as the stream is consumed.

§Examples
use dynamodb_facade::ScanRequest;
use futures_util::StreamExt;
use std::pin::pin;

let stream = ScanRequest::<PlatformTable>::new(client).stream();
// Must pin the stream
let mut stream = pin!(stream);

while let Some(result) = stream.next().await {
    let page /* : Vec<Item<PlatformTable>> */ = result?;
    for item in page {
        let _ = item;
    }
}

Auto Trait Implementations§

§

impl<TD, T, O, F, P> Freeze for ScanRequest<TD, T, O, F, P>

§

impl<TD, T = (), O = Raw, F = NoFilter, P = NoProjection> !RefUnwindSafe for ScanRequest<TD, T, O, F, P>

§

impl<TD, T, O, F, P> Send for ScanRequest<TD, T, O, F, P>
where TD: Send, T: Send, O: Send, F: Send, P: Send,

§

impl<TD, T, O, F, P> Sync for ScanRequest<TD, T, O, F, P>
where TD: Sync, T: Sync, O: Sync, F: Sync, P: Sync,

§

impl<TD, T, O, F, P> Unpin for ScanRequest<TD, T, O, F, P>
where TD: Unpin, T: Unpin, O: Unpin, F: Unpin, P: Unpin,

§

impl<TD, T, O, F, P> UnsafeUnpin for ScanRequest<TD, T, O, F, P>

§

impl<TD, T = (), O = Raw, F = NoFilter, P = NoProjection> !UnwindSafe for ScanRequest<TD, T, O, F, P>

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