pub struct Filter { /* private fields */ }Expand description
A filter an application adds for its templates, on top of the built-in ones.
use laravel_template_engine::{ArgKind, Filter, Value};
let sku = Filter::new("sku", "Formats a product code", |value: Value, _args: &[Value]| {
Ok(Value::from(format!("SKU-{value}")))
});
let shout = Filter::new("shout", "Adds exclamation marks", |value: Value, args: &[Value]| {
let count = args.first().and_then(|n| n.as_usize()).unwrap_or(1);
Ok(Value::from(format!("{value}{}", "!".repeat(count))))
})
.arg("count", ArgKind::Number, false);Implementations§
Source§impl Filter
impl Filter
Sourcepub fn new<F>(name: &'static str, description: &'static str, run: F) -> Self
pub fn new<F>(name: &'static str, description: &'static str, run: F) -> Self
A filter called name that runs run with the value and the arguments.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Filter
impl !UnwindSafe for Filter
impl Forget for Filter
impl Freeze for Filter
impl Move for Filter
impl Send for Filter
impl Sync for Filter
impl Unpin for Filter
impl UnsafeUnpin for Filterwhere
&'static str: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Arg>: UnsafeUnpin,
*const ArcInner<dyn Fn(Value, &[Value]) -> Result<Value, String> + Sync + Send> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(Value, &[Value]) -> Result<Value, String> + Sync + Send>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<K> ForeignKey<K> for K
impl<K> ForeignKey<K> for K
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more