pub struct Context { /* private fields */ }Expand description
The variables a single render can see.
Not to be confused with rustlavel_core::Context, which is the
application’s long-lived typed state. This one is per-render, cheap, and
intentionally untyped: a view is the one place where the shape of the data
is decided by whoever is editing the HTML.
use rustlavel_core::Json;
use rustlavel_view::Context;
let context = Context::new()
.with("title", "Dashboard")
.with("user", Json::object([("name", Json::from("Ada"))]));
assert_eq!(context.get("title").unwrap(), &Json::from("Dashboard"));Implementations§
Source§impl Context
impl Context
pub fn new() -> Self
Sourcepub fn with(self, key: impl Into<String>, value: impl Into<Json>) -> Self
pub fn with(self, key: impl Into<String>, value: impl Into<Json>) -> Self
Add a variable, chaining: Context::new().with("user", user).
Sourcepub fn insert(&mut self, key: impl Into<String>, value: impl Into<Json>)
pub fn insert(&mut self, key: impl Into<String>, value: impl Into<Json>)
Add a variable to an existing context.
pub fn get(&self, key: &str) -> Option<&Json>
Trait Implementations§
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
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
Mutably borrows from an owned value. Read more