Struct cedar_policy_core::ast::Name
source · pub struct Name { /* private fields */ }
Expand description
This is the Name
type used to name types, functions, etc.
The name can include namespaces.
Clone is O(1).
Implementations§
source§impl Name
impl Name
sourcepub fn new(
basename: Id,
path: impl IntoIterator<Item = Id>,
loc: Option<Loc>,
) -> Self
pub fn new( basename: Id, path: impl IntoIterator<Item = Id>, loc: Option<Loc>, ) -> Self
A full constructor for Name
sourcepub fn unqualified_name(id: Id) -> Self
pub fn unqualified_name(id: Id) -> Self
Create a Name
with no path (no namespaces).
sourcepub fn parse_unqualified_name(s: &str) -> Result<Self, ParseErrors>
pub fn parse_unqualified_name(s: &str) -> Result<Self, ParseErrors>
Create a Name
with no path (no namespaces).
Returns an error if s
is not a valid identifier.
sourcepub fn type_in_namespace(
basename: Id,
namespace: Name,
loc: Option<Loc>,
) -> Name
pub fn type_in_namespace( basename: Id, namespace: Name, loc: Option<Loc>, ) -> Name
Given a type basename and a namespace (as a Name
itself),
return a Name
representing the type’s fully qualified name
sourcepub fn namespace_components(&self) -> impl Iterator<Item = &Id>
pub fn namespace_components(&self) -> impl Iterator<Item = &Id>
Get the namespace of the Name
, as components
sourcepub fn namespace(&self) -> String
pub fn namespace(&self) -> String
Get the full namespace of the Name
, as a single string.
Examples:
foo::bar
–> the namespace is"foo"
bar
–> the namespace is""
foo::bar::baz
–> the namespace is"foo::bar"
sourcepub fn prefix_namespace_if_unqualified(&self, namespace: Option<Name>) -> Name
pub fn prefix_namespace_if_unqualified(&self, namespace: Option<Name>) -> Name
Prefix the name with a optional namespace
When the name is not an Id
, it doesn’t make sense to prefix any
namespace and hence this method returns a copy of self
When the name is an Id
, prefix it with the optional namespace
e.g., prefix A::B`` with
Some(C)or
Noneproduces
A::Bprefix
Awith
Some(B::C)yields
B::C::A`
sourcepub fn is_unqualified(&self) -> bool
pub fn is_unqualified(&self) -> bool
Test if a Name
is an Id
Trait Implementations§
source§impl<'de> Deserialize<'de> for Name
impl<'de> Deserialize<'de> for Name
Deserialize a Name
using from_normalized_str
This deserialization implementation is used in the JSON schema format.
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl FromNormalizedStr for Name
impl FromNormalizedStr for Name
source§fn describe_self() -> &'static str
fn describe_self() -> &'static str
Self
type, to be used in error messages.
What are we trying to parse?source§fn from_normalized_str(s: &str) -> Result<Self, ParseErrors>
fn from_normalized_str(s: &str) -> Result<Self, ParseErrors>
Self
by parsing a string, which is required to be normalized.
That is, the input is required to roundtrip with the Display
impl on Self
:
Self::from_normalized_str(x).to_string() == x
must hold. Read moresource§impl Ord for Name
impl Ord for Name
source§impl PartialOrd for Name
impl PartialOrd for Name
source§impl Serialize for Name
impl Serialize for Name
Serialize a Name
using its Display
implementation
This serialization implementation is used in the JSON schema format.
source§impl TryFrom<Name> for Id
impl TryFrom<Name> for Id
Convert a Name
to an Id
The error type is the unit type because the reason the conversion fails
is obvious
impl Eq for Name
Auto Trait Implementations§
impl Freeze for Name
impl RefUnwindSafe for Name
impl Send for Name
impl Sync for Name
impl Unpin for Name
impl UnwindSafe for Name
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more