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
impl Abbreviations
Sourcepub fn with_abbreviation(
self,
qualified_name: &str,
) -> Result<Self, AbbrevError>
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"));Sourcepub fn from_qualified_names(names: &[&str]) -> Result<Self, AbbrevError>
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();Sourcepub fn as_map(&self) -> &HashMap<String, String>
pub fn as_map(&self) -> &HashMap<String, String>
Get the underlying map of short names to fully-qualified names.
Trait Implementations§
Source§impl Clone for Abbreviations
impl Clone for Abbreviations
Source§fn clone(&self) -> Abbreviations
fn clone(&self) -> Abbreviations
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Abbreviations
impl Debug for Abbreviations
Source§impl Default for Abbreviations
impl Default for Abbreviations
Source§fn default() -> Abbreviations
fn default() -> Abbreviations
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for Abbreviations
impl RefUnwindSafe for Abbreviations
impl Send for Abbreviations
impl Sync for Abbreviations
impl Unpin for Abbreviations
impl UnsafeUnpin for Abbreviations
impl UnwindSafe for Abbreviations
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