Skip to main content

ResourceDef

Struct ResourceDef 

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

ResourceDef describes an entry in resources table

A resource definition can have several path patterns, a path matches the resource if it matches any of them. The first pattern is the primary one, it is used by pattern() and for building resource paths.

Implementations§

Source§

impl ResourceDef

Source

pub fn new<T>(path: T) -> ResourceDef
where T: IntoPattern,

Parse path patterns and create new ResourceDef instance.

Path segments are separated by /, a leading / is optional. Static segments could be case insensitive.

Panics if path pattern is malformed.

Source

pub fn prefix<T>(path: T) -> ResourceDef
where T: IntoPattern,

Parse path patterns and create new prefix ResourceDef instance.

A prefix resource matches paths that start with one of its patterns.

Panics if path pattern is malformed.

Source

pub fn root_prefix<T>(path: T) -> ResourceDef
where T: IntoPattern,

Parse path patterns and create new prefix ResourceDef instance.

Same as prefix(), but inserts / to the start of the patterns that do not have it.

Panics if path pattern is malformed.

Source

pub fn id(&self) -> u16

Resource id, 0 by default

A matched resource is reported with this id, see ResourceId.

Source

pub fn set_id(&mut self, id: u16)

Set resource id

Source

pub fn is_prefix(&self) -> bool

Check if the resource is a prefix resource, see prefix()

Source

pub fn name(&self) -> &str

Resource name, empty by default

Source

pub fn set_name<N>(&mut self, name: N)
where N: Into<String>,

Set resource name

Source

pub fn pattern(&self) -> &str

Primary path pattern of the resource, the first one

Source

pub fn patterns(&self) -> &[String]

All path patterns of the resource

Source

pub fn build_path<U, I>(&self, path: &mut String, elements: U) -> bool
where U: IntoIterator<Item = I>, I: AsRef<str>,

Build resource path from elements, using the primary pattern.

Elements are used for dynamic segments in pattern order, an iterator can be passed by &mut to continue using it afterwards. The path is appended to path. Returns false if there are not enough elements, path is left unchanged then.

Source

pub fn build_path_named<K, V, S>( &self, path: &mut String, elements: &HashMap<K, V, S>, ) -> bool
where K: Borrow<str> + Eq + Hash, V: AsRef<str>, S: BuildHasher,

Build resource path from named elements, using the primary pattern.

The path is appended to path. Returns false if an element is missing, path is left unchanged then.

Trait Implementations§

Source§

impl Clone for ResourceDef

Source§

fn clone(&self) -> ResourceDef

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 ResourceDef

Source§

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

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

impl Eq for ResourceDef

Source§

impl<'a> From<&'a str> for ResourceDef

Source§

fn from(path: &'a str) -> ResourceDef

Converts to this type from the input type.
Source§

impl From<&String> for ResourceDef

Source§

fn from(path: &String) -> ResourceDef

Converts to this type from the input type.
Source§

impl From<String> for ResourceDef

Source§

fn from(path: String) -> ResourceDef

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for ResourceDef
where T: AsRef<str>,

Source§

fn from(paths: Vec<T>) -> ResourceDef

Converts to this type from the input type.
Source§

impl<T, const N: usize> From<[T; N]> for ResourceDef
where T: AsRef<str>,

Source§

fn from(paths: [T; N]) -> ResourceDef

Converts to this type from the input type.
Source§

impl Hash for ResourceDef

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ResourceDef

Source§

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

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

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

Inequality operator !=. Read more

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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 = 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.