pub struct InternalName { /* private fields */ }
Expand description
Represents the name of an entity type, function, etc. The name may include namespaces. Clone is O(1).
This type may contain any name valid for use internally, including names
with reserved __cedar
components (and also names without __cedar
).
Implementations§
Source§impl InternalName
impl InternalName
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 InternalName
Sourcepub fn unqualified_name(id: Id) -> Self
pub fn unqualified_name(id: Id) -> Self
Create an InternalName
with no path (no namespaces).
Sourcepub fn __cedar() -> Self
pub fn __cedar() -> Self
Get the InternalName
representing the reserved __cedar
namespace
Sourcepub fn parse_unqualified_name(s: &str) -> Result<Self, ParseErrors>
pub fn parse_unqualified_name(s: &str) -> Result<Self, ParseErrors>
Create an InternalName
with no path (no namespaces).
Returns an error if s
is not a valid identifier.
Sourcepub fn type_in_namespace(
basename: Id,
namespace: InternalName,
loc: Option<Loc>,
) -> InternalName
pub fn type_in_namespace( basename: Id, namespace: InternalName, loc: Option<Loc>, ) -> InternalName
Given a type basename and a namespace (as an InternalName
itself),
return an InternalName
representing the type’s fully qualified name
Sourcepub fn basename(&self) -> &Id
pub fn basename(&self) -> &Id
Get the basename of the InternalName
(ie, with namespaces stripped).
Sourcepub fn namespace_components(&self) -> impl Iterator<Item = &Id>
pub fn namespace_components(&self) -> impl Iterator<Item = &Id>
Get the namespace of the InternalName
, as components
Sourcepub fn namespace(&self) -> String
pub fn namespace(&self) -> String
Get the full namespace of the InternalName
, 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 qualify_with(&self, namespace: Option<&InternalName>) -> InternalName
pub fn qualify_with(&self, namespace: Option<&InternalName>) -> InternalName
Qualify the name with a namespace
If the name already has a non-empty namespace, this method does not
apply any prefix and instead returns a copy of self
.
If namespace
is None
, that represents the empty namespace, so no
prefixing will be done.
If the name does not already have an explicit namespace (i.e., it’s
just a single Id
), this applies namespace
as a prefix (if it is
present).
Examples:
A::B
.qualify_with(None) isA::B
A::B
.qualify_with(Some(C)) is alsoA::B
A
.qualify_with(None) isA
A
.qualify_with(Some(C)) isC::A
A
.qualify_with(Some(B::C)) isB::C::A
Sourcepub fn qualify_with_name(&self, namespace: Option<&Name>) -> InternalName
pub fn qualify_with_name(&self, namespace: Option<&Name>) -> InternalName
Like qualify_with()
, but accepts a Name
as the namespace to qualify with
Sourcepub fn is_unqualified(&self) -> bool
pub fn is_unqualified(&self) -> bool
Test if an InternalName
is an Id
Sourcepub fn is_reserved(&self) -> bool
pub fn is_reserved(&self) -> bool
Test if an InternalName
is reserved
i.e., any of its components matches __cedar
Trait Implementations§
Source§impl AsRef<InternalName> for Name
impl AsRef<InternalName> for Name
Source§fn as_ref(&self) -> &InternalName
fn as_ref(&self) -> &InternalName
Source§impl Clone for InternalName
impl Clone for InternalName
Source§fn clone(&self) -> InternalName
fn clone(&self) -> InternalName
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for InternalName
impl Debug for InternalName
Source§impl<'de> Deserialize<'de> for InternalName
impl<'de> Deserialize<'de> for InternalName
Deserialize an InternalName
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 Display for InternalName
impl Display for InternalName
Source§impl From<Id> for InternalName
impl From<Id> for InternalName
A shortcut for InternalName::unqualified_name
Source§impl From<Name> for InternalName
impl From<Name> for InternalName
Source§impl FromNormalizedStr for InternalName
impl FromNormalizedStr for InternalName
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 FromStr for InternalName
impl FromStr for InternalName
Source§impl Hash for InternalName
impl Hash for InternalName
Source§impl Ord for InternalName
impl Ord for InternalName
Source§impl PartialEq for InternalName
impl PartialEq for InternalName
PartialEq
implementation ignores the loc
.
Source§impl PartialOrd for InternalName
impl PartialOrd for InternalName
Source§impl Serialize for InternalName
impl Serialize for InternalName
Serialize an InternalName
using its Display
implementation
This serialization implementation is used in the JSON schema format.
Source§impl<'a> TryFrom<&'a InternalName> for &'a Name
impl<'a> TryFrom<&'a InternalName> for &'a Name
Source§type Error = ReservedNameError
type Error = ReservedNameError
Source§fn try_from(value: &'a InternalName) -> Result<&'a Name, ReservedNameError>
fn try_from(value: &'a InternalName) -> Result<&'a Name, ReservedNameError>
Source§impl TryFrom<InternalName> for Id
impl TryFrom<InternalName> for Id
Convert a InternalName
to an Id
The error type is the unit type because the reason the conversion fails
is obvious
Source§impl TryFrom<InternalName> for Name
impl TryFrom<InternalName> for Name
Source§type Error = ReservedNameError
type Error = ReservedNameError
impl Eq for InternalName
Auto Trait Implementations§
impl Freeze for InternalName
impl RefUnwindSafe for InternalName
impl Send for InternalName
impl Sync for InternalName
impl Unpin for InternalName
impl UnwindSafe for InternalName
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