Skip to main content

AttributeBag

Struct AttributeBag 

Source
pub struct AttributeBag { /* private fields */ }
Expand description

An ordered collection of attributes supplied to a component or slot.

Implementations§

Source§

impl AttributeBag

Source

pub fn new(attributes: Attributes) -> Self

Create a bag from raw attributes. Each value retains its current escaping.

Source

pub fn all(&self) -> &Attributes

The raw attributes, including null values and omitted Boolean attributes.

Source

pub fn all_for(&self, keys: &[&str]) -> Attributes

Return the raw attributes for the requested keys in their original order.

Source

pub fn first(&self) -> Option<&AttributeValue>

The first value, if the first entry exists and is non-null.

Source

pub fn get(&self, key: &str) -> Option<&AttributeValue>

Look up an exact key. Null values take the default path, as in Laravel.

Source

pub fn get_or_else( &self, key: &str, default: impl FnOnce() -> AttributeValue, ) -> AttributeValue

Find a value or lazily compute a fallback.

Source

pub fn first_or_else( &self, default: impl FnOnce() -> AttributeValue, ) -> AttributeValue

Retrieve the first value or lazily compute a fallback.

Source

pub fn only(&self, keys: &[&str]) -> Self

Retain the requested keys, in bag order.

Source

pub fn except(&self, keys: &[&str]) -> Self

Exclude the requested keys. Dotted names can also remove nested array entries.

Source

pub fn filter( &self, predicate: impl FnMut(&AttributeValue, &str) -> bool, ) -> Self

Retain entries whose value and key pass the callback.

Source

pub fn where_starts_with(&self, prefixes: &[&str]) -> Self

Retain keys that begin with any nonempty prefix.

Source

pub fn where_doesnt_start_with(&self, prefixes: &[&str]) -> Self

Retain keys that begin with none of the nonempty prefixes.

Source

pub fn that_start_with(&self, prefixes: &[&str]) -> Self

Alias for where_starts_with.

Source

pub fn extract_prop_names(names: &[&str]) -> Vec<String>

Expand template-facing prop names to include the name and Laravel’s kebab-case spelling.

Source

pub fn only_props(&self, names: &[&str]) -> Self

Retain prop attributes by their declared or kebab-case name.

Source

pub fn except_props(&self, names: &[&str]) -> Self

Exclude prop attributes by their declared or kebab-case name.

Source

pub fn has(&self, keys: &[&str]) -> bool

Whether all keys exist, including keys with null values and nested array paths.

Source

pub fn has_any(&self, keys: &[&str]) -> bool

Whether any key exists, including keys with null values and nested array paths.

Source

pub fn missing(&self, keys: &[&str]) -> bool

Whether at least one of the requested keys is missing.

Source

pub fn when<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, ) -> T

Apply a transformation when the Boolean condition holds.

The result can be a bag or a caller’s runtime value that can also hold the fallback bag.

Source

pub fn unless<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, ) -> T

Apply a transformation when the Boolean condition is false.

Source

pub fn when_else<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, default: impl FnOnce(&Self, bool) -> Option<T>, ) -> T

Apply either branch, falling back to the original bag if the selected callback returns null.

Source

pub fn unless_else<T: From<Self>>( &self, condition: bool, callback: impl FnOnce(&Self, bool) -> Option<T>, default: impl FnOnce(&Self, bool) -> Option<T>, ) -> T

Apply either branch, running the main callback when the condition is false.

Source

pub fn prepends(&self, value: impl Into<AttributeValue>) -> AttributeValue

Construct a default value which appends the provided attribute after the default.

Source

pub fn class(&self, entries: &[CssEntry<'_>]) -> Result<Self, AttributeError>

Merge a class list through the same escaped-default path as merge.

Source

pub fn style(&self, entries: &[CssEntry<'_>]) -> Result<Self, AttributeError>

Merge a style list, finishing each style with a semicolon.

Source

pub fn merge( &self, defaults: &Attributes, escape: bool, ) -> Result<Self, AttributeError>

Add defaults in their supplied order, optionally escaping them. Class, style and prepended defaults are joined with supplied values rather than being replaced.

Source

pub fn insert_literal( &mut self, name: impl Into<String>, value: impl Into<String>, )

Insert a compiler literal. An interpolated literal must already contain escaped echoes. The literal fragments and the rendered echoes retain their exact bytes here.

Source

pub fn insert_bound( &mut self, name: impl Into<String>, value: impl Into<AttributeValue>, )

Insert a bound attribute, applying Laravel’s sanitizeComponentAttribute rules.

Source

pub fn forward(&self, parent: &Self) -> Result<Self, AttributeError>

Forward a parent bag. Local attributes act as its unescaped defaults.

Source

pub fn get_attributes(&self) -> &Attributes

Read the underlying attributes, including omitted values.

Source

pub fn set_attributes(&mut self, attributes: Attributes)

Replace the raw attributes without escaping them.

Source

pub fn offset_exists(&self, key: &str) -> bool

Whether an offset is set and non-null, following PHP’s isset.

Source

pub fn offset_get(&self, key: &str) -> Option<&AttributeValue>

Access a non-null value by its exact key.

Source

pub fn offset_set( &mut self, key: impl Into<String>, value: impl Into<AttributeValue>, )

Set an offset without sanitizing the value.

Source

pub fn offset_unset(&mut self, key: &str)

Remove an offset, preserving the order of the remaining entries.

Source

pub fn get_iterator(&self) -> Iter<'_, String, AttributeValue> ⓘ

Iterate over the raw values in insertion order.

Source

pub fn json_serialize(&self) -> &Attributes

Return the raw map as a serialization input.

Source

pub fn to_array(&self) -> Attributes

Return the raw attributes as an ordered map.

Source

pub fn invoke(&self, defaults: &Attributes) -> Result<String, AttributeError>

Merge escaped defaults and render the result, as when a Blade bag is called.

Source

pub fn is_empty(&self) -> Result<bool, AttributeError>

Whether the bag renders to an empty string.

Source

pub fn is_not_empty(&self) -> Result<bool, AttributeError>

Whether the bag renders any HTML attributes.

Source

pub fn to_html(&self) -> Result<String, AttributeError>

Render the attributes using HTML encoding, preserving existing entities.

Trait Implementations§

Source§

impl Clone for AttributeBag

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AttributeBag

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AttributeBag

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Index<&str> for AttributeBag

Source§

type Output = AttributeValue

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a AttributeBag

Source§

type Item = (&'a String, &'a AttributeValue)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, String, AttributeValue>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl JsonValue for AttributeBag

Source§

fn json_kind(&self) -> JsonKind<'_>

Borrow the value’s encoding representation.
Source§

impl PartialEq for AttributeBag

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AttributeBag

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.