Skip to main content

Abbreviations

Struct Abbreviations 

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

A validated set of abbreviations mapping short names to fully-qualified names.

Abbreviations allow short names to be used instead of fully-qualified type names in CEL expressions. This is useful when working with protobuf types from multiple packages.

§Example

use cel_core::Abbreviations;

let abbrevs = Abbreviations::new()
    .with_abbreviation("my.package.Foo").unwrap()     // "Foo" -> "my.package.Foo"
    .with_abbreviation("other.package.Bar").unwrap(); // "Bar" -> "other.package.Bar"

assert_eq!(abbrevs.resolve("Foo"), Some("my.package.Foo"));
assert_eq!(abbrevs.resolve("Bar"), Some("other.package.Bar"));

Implementations§

Source§

impl Abbreviations

Source

pub fn new() -> Self

Create an empty abbreviations set.

Source

pub fn with_abbreviation( self, qualified_name: &str, ) -> Result<Self, AbbrevError>

Add an abbreviation for a qualified name.

The short name is derived from the last segment of the qualified name. Returns an error if the short name conflicts with an existing abbreviation.

§Example
use cel_core::Abbreviations;

let abbrevs = Abbreviations::new()
    .with_abbreviation("my.package.Foo").unwrap();

assert_eq!(abbrevs.resolve("Foo"), Some("my.package.Foo"));
Source

pub fn from_qualified_names(names: &[&str]) -> Result<Self, AbbrevError>

Create abbreviations from a slice of qualified names.

§Example
use cel_core::Abbreviations;

let abbrevs = Abbreviations::from_qualified_names(&[
    "my.package.Foo",
    "other.package.Bar",
]).unwrap();
Source

pub fn as_map(&self) -> &HashMap<String, String>

Get the underlying map of short names to fully-qualified names.

Source

pub fn resolve(&self, short_name: &str) -> Option<&str>

Resolve a short name to its fully qualified name.

Returns None if the short name is not in the abbreviations set.

Source

pub fn is_empty(&self) -> bool

Check if the abbreviations set is empty.

Source

pub fn len(&self) -> usize

Get the number of abbreviations.

Trait Implementations§

Source§

impl Clone for Abbreviations

Source§

fn clone(&self) -> Abbreviations

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Abbreviations

Source§

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

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

impl Default for Abbreviations

Source§

fn default() -> Abbreviations

Returns the “default value” for a type. 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
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.