[−][src]Struct roa_core::SyncContext
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]
&mut self,
_scope: SC,
name: &'a str,
value: T
) -> Option<Variable<'a, T>> where
SC: Any,
T: Any + Send + Sync,
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]
&mut self,
name: &'a str,
value: T
) -> Option<Variable<'a, T>> where
T: Any + Send + Sync,
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]
SC: Any,
T: Any + Send + Sync,
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]
T: Any + Send + Sync,
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<S> Deref for SyncContext<S>
[src]
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,
S: Send,
impl<S> Sync for SyncContext<S> where
S: Sync,
S: Sync,
impl<S> Unpin for SyncContext<S> where
S: Unpin,
S: Unpin,
impl<S> !UnwindSafe for SyncContext<S>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,