Skip to main content

MemorySlot

Struct MemorySlot 

Source
pub struct MemorySlot { /* private fields */ }
Expand description

A SessionSlot in memory (tests, examples, a single-process tool). Its Debug shows only the account id and whether a session and a cart are kept.

Implementations§

Source§

impl MemorySlot

Source

pub fn new(id: impl Into<String>, session: Option<Value>) -> Self

A slot for account id holding session.

Examples found in repository?
examples/fake_order.rs (line 15)
13async fn main() -> GrabResult<()> {
14    let backend = Fake::default();
15    let slot = Arc::new(MemorySlot::new("acct-1", Some(Fake::session("Sample"))));
16    let client = backend.client(slot);
17
18    let found = client.search("ramen", 5).await?;
19    println!("{}\n", text::merchants(&found));
20
21    let menu = client.menu("fake-ramen").await?;
22    println!("{}\n", text::menu(&menu, None));
23
24    let cart = client
25        .cart(&CartOp::Add {
26            merchant_id: menu.merchant.id.clone(),
27            item_id: menu.items[0].id.clone(),
28            quantity: 2,
29            note: Some("less salt".into()),
30        })
31        .await?;
32    println!("{}\n", text::cart(&cart));
33
34    let quote = client.quote().await?;
35    println!("{}\n", text::quote(&quote));
36
37    // Only once the person agreed to this quote id; never retried.
38    let placed = client.place_order(&quote.quote_id).await?;
39    println!("placed {}\n", placed.order_id);
40    println!("{}", text::tracked(&client.track(None).await?));
41    Ok(())
42}
Source

pub fn session(&self) -> Option<Value>

The session now (as the backend last saved it).

Source

pub fn cart(&self) -> Option<Value>

The kept cart now.

Trait Implementations§

Source§

impl Debug for MemorySlot

Source§

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

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

impl Default for MemorySlot

Source§

fn default() -> Self

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

impl SessionSlot for MemorySlot

Source§

fn id(&self) -> &str

Whose (the account’s key): keys what the backend keeps per account.
Source§

fn load<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = GrabResult<Option<Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The session (none: not connected).
Source§

fn save<'life0, 'life1, 'async_trait>( &'life0 self, session: &'life1 Value, ) -> Pin<Box<dyn Future<Output = GrabResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Keep the session (a refresh renewed it).
Source§

fn load_cart<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = GrabResult<Option<Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The backend’s cart, kept beside the session (none: empty).
Source§

fn save_cart<'life0, 'life1, 'async_trait>( &'life0 self, cart: Option<&'life1 Value>, ) -> Pin<Box<dyn Future<Output = GrabResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Keep (none: drop) the cart.

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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