pub struct LifetimeEnv {
pub(crate) nodes: Vec<LifetimeNode>,
}
Expand description
A lifetime dependency graph used for tracking which lifetimes outlive, and are outlived by, other lifetimes.
It is similar to [syn::LifetimeDef
], except it can also track lifetime
bounds defined in the where
clause.
Fields§
§nodes: Vec<LifetimeNode>
Implementations§
source§impl LifetimeEnv
impl LifetimeEnv
sourcefn new() -> Self
fn new() -> Self
Construct an empty LifetimeEnv
.
To create one outside of this module, use LifetimeEnv::from_method_item
or LifetimeEnv::from
on &syn::Generics
.
sourcepub fn names(&self) -> impl Iterator<Item = &NamedLifetime> + Clone
pub fn names(&self) -> impl Iterator<Item = &NamedLifetime> + Clone
Iterate through the names of the lifetimes in scope.
sourcepub fn from_method_item(
method: &ImplItemFn,
impl_generics: Option<&Generics>,
self_param: Option<&SelfParam>,
params: &[Param],
return_type: Option<&TypeName>,
) -> Self
pub fn from_method_item( method: &ImplItemFn, impl_generics: Option<&Generics>, self_param: Option<&SelfParam>, params: &[Param], return_type: Option<&TypeName>, ) -> Self
Returns a LifetimeEnv
for a method, accounting for lifetimes and bounds
defined in both the impl block and the method, as well as implicit lifetime
bounds in the optional self
param, other param, and optional return type.
For example, the type &'a Foo<'b>
implies 'b: 'a
.
sourcepub fn from_struct_item(
strct: &ItemStruct,
fields: &[(Ident, TypeName, Docs)],
) -> Self
pub fn from_struct_item( strct: &ItemStruct, fields: &[(Ident, TypeName, Docs)], ) -> Self
Returns a LifetimeEnv
for a struct, accounding for lifetimes and bounds
defined in the struct generics, as well as implicit lifetime bounds in
the struct’s fields. For example, the field &'a Foo<'b>
implies 'b: 'a
.
sourcefn extend_implicit_lifetime_bounds(
&mut self,
typ: &TypeName,
behind_ref: Option<&NamedLifetime>,
)
fn extend_implicit_lifetime_bounds( &mut self, typ: &TypeName, behind_ref: Option<&NamedLifetime>, )
Traverse a type, adding any implicit lifetime bounds that arise from
having a reference to an opaque containing a lifetime.
For example, the type &'a Foo<'b>
implies 'b: 'a
.
sourcefn extend_generics(&mut self, generics: &Generics)
fn extend_generics(&mut self, generics: &Generics)
Add the lifetimes from generic parameters and where bounds.
sourcepub fn lifetimes_to_tokens(&self) -> TokenStream
pub fn lifetimes_to_tokens(&self) -> TokenStream
<'a, 'b, 'c>
Write the existing lifetimes, excluding bounds, as generic parameters.
To include lifetime bounds, use [LifetimeEnv::lifetime_defs_to_tokens
].
sourcepub(crate) fn id<L>(&self, lifetime: &L) -> Option<usize>where
NamedLifetime: PartialEq<L>,
pub(crate) fn id<L>(&self, lifetime: &L) -> Option<usize>where
NamedLifetime: PartialEq<L>,
Returns the index of a lifetime in the graph, or None
if the lifetime
isn’t in the graph.
sourcefn extend_lifetimes<'a, L, I>(&mut self, iter: I)
fn extend_lifetimes<'a, L, I>(&mut self, iter: I)
Add isolated lifetimes to the graph.
sourcefn extend_bounds<'a, L, B, I>(&mut self, iter: I)where
NamedLifetime: PartialEq<L> + From<&'a L>,
L: 'a,
B: IntoIterator<Item = &'a L>,
I: IntoIterator<Item = (&'a L, B)>,
fn extend_bounds<'a, L, B, I>(&mut self, iter: I)where
NamedLifetime: PartialEq<L> + From<&'a L>,
L: 'a,
B: IntoIterator<Item = &'a L>,
I: IntoIterator<Item = (&'a L, B)>,
Add edges to the lifetime graph.
This method is decoupled from LifetimeEnv::extend_lifetimes
because
generics can define new lifetimes, while where
clauses cannot.
§Panics
This method panics if any of the lifetime bounds aren’t already defined
in the graph. This isn’t allowed by rustc in the first place, so it should
only ever occur when deserializing an invalid LifetimeEnv
.
Trait Implementations§
source§impl Clone for LifetimeEnv
impl Clone for LifetimeEnv
source§fn clone(&self) -> LifetimeEnv
fn clone(&self) -> LifetimeEnv
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for LifetimeEnv
impl Debug for LifetimeEnv
source§impl<'de> Deserialize<'de> for LifetimeEnv
impl<'de> Deserialize<'de> for LifetimeEnv
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 LifetimeEnv
impl Display for LifetimeEnv
source§impl Hash for LifetimeEnv
impl Hash for LifetimeEnv
source§impl PartialEq for LifetimeEnv
impl PartialEq for LifetimeEnv
source§impl Serialize for LifetimeEnv
impl Serialize for LifetimeEnv
Serialize a LifetimeEnv
as a map from lifetimes to their bounds.
source§impl ToTokens for LifetimeEnv
impl ToTokens for LifetimeEnv
source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
impl Eq for LifetimeEnv
impl StructuralPartialEq for LifetimeEnv
Auto Trait Implementations§
impl Freeze for LifetimeEnv
impl RefUnwindSafe for LifetimeEnv
impl Send for LifetimeEnv
impl Sync for LifetimeEnv
impl Unpin for LifetimeEnv
impl UnwindSafe for LifetimeEnv
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> Spanned for T
impl<T> Spanned for T
source§fn span(&self) -> Span
fn span(&self) -> Span
Span
covering the complete contents of this syntax tree
node, or Span::call_site()
if this node is empty.