pub struct TypeKey { /* private fields */ }Expand description
The canonical type identity, which the source model owns — re-exported
here because the registry’s tables are keyed by it.
Canonical type-shape key: identity is the token string of the
normalized type. Normalization is a closed rule set — group/paren
unwrap, a crate::/self::/source-module path reduced to its final
segment, and a prelude path read as the bare name the language knows it
by (std::vec::Vec<Foo> ≡ Vec<Foo>) — and any spelling it does not
cover is kept verbatim.
§A key is an identity, and nothing else
It is what a table is indexed by. It is not a route to syn::Type: the
only way to reach a type’s syntax is
Conversions::reading (in the registry layer above) followed by
TypeRef, because a
reading is what pairs a spelling with the classification that vouches for
it.
This used to keep the parsed form beside the string and hand it out through
to_type(), which let any holder of a key produce tokens for a type the
model never classified — the same capability #280 sealed TypeRef against,
granted by the key itself. A caller that wants tokens now has to have gotten
them from somewhere that knows what they mean: the registry’s reading, or
the declaration that wrote them (#291).
What a key can still answer about itself is what it is called —
Self::as_str, Self::ident, Self::short_name — because a name is
not syntax.
Implementations§
Source§impl TypeKey
impl TypeKey
Sourcepub fn parse(s: &str) -> Result<TypeKey, TypeKeyParseError>
pub fn parse(s: &str) -> Result<TypeKey, TypeKeyParseError>
Build a key by parsing the input as a type and normalizing.
The parse is kept for validation and then discarded: a key that cannot be a type is a mistake worth reporting at the declaration, and a key that can is still only its canonical string.
Sourcepub fn from_type(ty: &Type) -> TypeKey
pub fn from_type(ty: &Type) -> TypeKey
Build a key directly from a syn::Type (normalizing a clone; the
input is not modified).
Sourcepub fn from_ident(ident: &Ident) -> TypeKey
pub fn from_ident(ident: &Ident) -> TypeKey
Build a key for a bare item ident — infallible by construction (an ident IS a single-segment path type; nothing to parse or normalize).
Sourcepub fn ident(&self) -> Option<Ident>
pub fn ident(&self) -> Option<Ident>
The bare item ident this key names — Foo, a::Foo → Foo,
a::Foo<u8>::Bar → Bar; None when the last segment carries
generic arguments (Vec<u8> names no bare item) or the key is not a
path.
Matches bare_path_ident on the
same type — a correspondence this crate’s tests pin.
A name is not syntax, which is why this is the key’s business and
producing a syn::Type is not. A caller that wants to look a declared
item up by name was never asking for tokens; it was asking the key what
it is called (#291).
Sourcepub fn short_name(&self) -> Option<String>
pub fn short_name(&self) -> Option<String>
The last path segment’s ident, ignoring its generic arguments —
Publisher<'static> → "Publisher", a::Foo<u8>::Bar → "Bar".
None for anything that is not a path.
The looser sibling of Self::ident, for the callers that derive a
destination-language class name from a Rust type: a declaration writes
ptr_class!(Publisher<'static>) and means the class Publisher.
Trait Implementations§
impl Eq for TypeKey
Source§impl Ord for TypeKey
impl Ord for TypeKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
impl !Send for TypeKey
impl !Sync for TypeKey
impl Freeze for TypeKey
impl RefUnwindSafe for TypeKey
impl Unpin for TypeKey
impl UnsafeUnpin for TypeKey
impl UnwindSafe for TypeKey
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§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