Attr

Struct Attr 

Source
pub struct Attr {
    pub ns: Option<&'static str>,
    pub key: &'static str,
    pub data: OxRef<'static>,
}
Expand description

An attribute attaches metadata to a container or a field

Attributes use syntax like #[facet(sensitive)] for builtins or #[facet(orm::primary_key)] for namespaced extension attributes.

The derive macro expands attributes to macro invocations that return Attr values with typed data.

Fields§

§ns: Option<&'static str>

The namespace (e.g., Some(“orm”) in #[facet(orm::primary_key)]). None for builtin attributes like #[facet(sensitive)].

§key: &'static str

The key (e.g., “primary_key” in #[facet(orm::primary_key)])

§data: OxRef<'static>

Data stored by the attribute

Implementations§

Source§

impl Attr

Source

pub const fn new<T: Facet<'static> + Sized>( ns: Option<&'static str>, key: &'static str, data: &'static T, ) -> Self

Create a new attribute with typed data.

The data must be a static reference to a sized value that implements Facet. The Sized bound is required to allow const construction.

Source

pub const fn new_shape( ns: Option<&'static str>, key: &'static str, shape: &'static Shape, ) -> Self

Create a new attribute storing a Shape reference.

This is a convenience method for shape_type variants. Since Shape: Facet<'static>, this just delegates to new.

Source

pub const fn is_builtin(&self) -> bool

Returns true if this is a builtin attribute (no namespace).

Source

pub fn get_as<T: Facet<'static>>(&self) -> Option<&T>

Get a typed reference to the attribute data if the shape matches T::SHAPE.

Returns None if the stored shape doesn’t match the expected type.

Trait Implementations§

Source§

impl Debug for Attr

Source§

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

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

impl Facet<'_> for Attr

Source§

const SHAPE: &'static Shape

The shape of this type, including: whether it’s a Struct, an Enum, something else? Read more
Source§

impl PartialEq for Attr

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Send for Attr

Source§

impl Sync for Attr

Auto Trait Implementations§

§

impl Freeze for Attr

§

impl RefUnwindSafe for Attr

§

impl Unpin for Attr

§

impl UnwindSafe for Attr

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.