pub struct ContextBuilder { /* private fields */ }Expand description
Builder for constructing template context
This provides a fluent API for building template context without needing to create a struct for simple cases.
§Example
ⓘ
use rustapi_view::ContextBuilder;
let context = ContextBuilder::new()
.insert("name", "Alice")
.insert("age", 30)
.insert_if("admin", true, |_| user.is_admin())
.build();Implementations§
Source§impl ContextBuilder
impl ContextBuilder
Sourcepub fn insert<T: Serialize + ?Sized>(
self,
key: impl Into<String>,
value: &T,
) -> Self
pub fn insert<T: Serialize + ?Sized>( self, key: impl Into<String>, value: &T, ) -> Self
Insert a value into the context
Sourcepub fn insert_if<T: Serialize + ?Sized, F>(
self,
key: impl Into<String>,
value: &T,
condition: F,
) -> Self
pub fn insert_if<T: Serialize + ?Sized, F>( self, key: impl Into<String>, value: &T, condition: F, ) -> Self
Insert a value if a condition is met
Sourcepub fn insert_some<T: Serialize + ?Sized>(
self,
key: impl Into<String>,
value: Option<&T>,
) -> Self
pub fn insert_some<T: Serialize + ?Sized>( self, key: impl Into<String>, value: Option<&T>, ) -> Self
Insert a value if it’s Some
Trait Implementations§
Source§impl Default for ContextBuilder
impl Default for ContextBuilder
Source§impl From<ContextBuilder> for Context
impl From<ContextBuilder> for Context
Source§fn from(builder: ContextBuilder) -> Self
fn from(builder: ContextBuilder) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ContextBuilder
impl RefUnwindSafe for ContextBuilder
impl Send for ContextBuilder
impl Sync for ContextBuilder
impl Unpin for ContextBuilder
impl UnwindSafe for ContextBuilder
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