[][src]Struct roa_core::SyncContext

pub struct SyncContext<S> {
    pub exec: Executor,
    pub remote_addr: SocketAddr,
    // some fields omitted
}

Sync parts of Context.

Fields

exec: Executor

Application level runtime.

remote_addr: SocketAddr

Socket addr of last client or proxy.

Methods

impl<S> SyncContext<S>[src]

pub fn store_scoped<'a, SC, T>(
    &mut self,
    _scope: SC,
    name: &'a str,
    value: T
) -> Option<Variable<'a, T>> where
    SC: Any,
    T: Any + Send + Sync
[src]

Store key-value pair in specific scope.

Example

use roa_core::App;
use roa_core::http::{StatusCode, Method};

struct Scope;
struct AnotherScope;

let mut app = App::new(());
app.gate_fn(|mut ctx, next| async move {
    ctx.store_scoped(Scope, "id", "1".to_string());
    next.await
});
app.end(|ctx| async move {
    assert_eq!(1, ctx.load_scoped::<Scope, String>("id").unwrap().parse::<i32>()?);
    assert!(ctx.load_scoped::<AnotherScope, String>("id").is_none());
    Ok(())
});

pub fn store<'a, T>(
    &mut self,
    name: &'a str,
    value: T
) -> Option<Variable<'a, T>> where
    T: Any + Send + Sync
[src]

Store key-value pair in public scope.

Example

use roa_core::App;
use roa_core::http::{StatusCode, Method};

let mut app = App::new(());
app.gate_fn(|mut ctx, next| async move {
    ctx.store("id", "1".to_string());
    next.await
});
app.end(|ctx| async move {
    assert_eq!(1, ctx.load::<String>("id").unwrap().parse::<i32>()?);
    Ok(())
});

pub fn load_scoped<'a, SC, T>(&self, name: &'a str) -> Option<Variable<'a, T>> where
    SC: Any,
    T: Any + Send + Sync
[src]

Search for value by key in specific scope.

Example

use roa_core::App;

struct Scope;

let mut app = App::new(());
app.gate_fn(|mut ctx, next| async move {
    ctx.store_scoped(Scope, "id", "1".to_owned());
    next.await
});
app.end(|ctx| async move {
    assert_eq!(1, ctx.load_scoped::<Scope, String>("id").unwrap().parse::<i32>()?);
    Ok(())
});

pub fn load<'a, T>(&self, name: &'a str) -> Option<Variable<'a, T>> where
    T: Any + Send + Sync
[src]

Search for value by key in public scope.

Example

use roa_core::App;

let mut app = App::new(());
app.gate_fn(|mut ctx, next| async move {
    ctx.store("id", "1".to_string());
    next.await
});
app.end(|ctx| async move {
    assert_eq!(1, ctx.load::<String>("id").unwrap().parse::<i32>()?);
    Ok(())
});

Trait Implementations

impl<S: Clone> Clone for SyncContext<S>[src]

impl<S> Deref for SyncContext<S>[src]

type Target = S

The resulting type after dereferencing.

impl<S> DerefMut for SyncContext<S>[src]

Auto Trait Implementations

impl<S> !RefUnwindSafe for SyncContext<S>

impl<S> Send for SyncContext<S> where
    S: Send

impl<S> Sync for SyncContext<S> where
    S: Sync

impl<S> Unpin for SyncContext<S> where
    S: Unpin

impl<S> !UnwindSafe for SyncContext<S>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.