diplomat_core::ast

Struct LifetimeEnv

source
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

source

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.

source

pub fn names(&self) -> impl Iterator<Item = &NamedLifetime> + Clone

Iterate through the names of the lifetimes in scope.

source

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.

source

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.

source

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.

source

fn extend_generics(&mut self, generics: &Generics)

Add the lifetimes from generic parameters and where bounds.

source

pub fn len(&self) -> usize

Returns the number of lifetimes in the graph.

source

pub fn is_empty(&self) -> bool

Returns true if the graph contains no lifetimes.

source

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].

source

pub(crate) fn id<L>(&self, lifetime: &L) -> Option<usize>

Returns the index of a lifetime in the graph, or None if the lifetime isn’t in the graph.

source

fn extend_lifetimes<'a, L, I>(&mut self, iter: I)
where NamedLifetime: PartialEq<L> + From<&'a L>, L: 'a, I: IntoIterator<Item = &'a L>,

Add isolated lifetimes to the graph.

source

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

source§

fn clone(&self) -> LifetimeEnv

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LifetimeEnv

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for LifetimeEnv

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for LifetimeEnv

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for LifetimeEnv

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for LifetimeEnv

source§

fn eq(&self, other: &LifetimeEnv) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for LifetimeEnv

Serialize a LifetimeEnv as a map from lifetimes to their bounds.

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl ToTokens for LifetimeEnv

source§

fn to_tokens(&self, tokens: &mut TokenStream)

Write self to the given TokenStream. Read more
source§

fn to_token_stream(&self) -> TokenStream

Convert self directly into a TokenStream object. Read more
source§

fn into_token_stream(self) -> TokenStream
where Self: Sized,

Convert self directly into a TokenStream object. Read more
source§

impl Eq for LifetimeEnv

source§

impl StructuralPartialEq for LifetimeEnv

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Spanned for T
where T: Spanned + ?Sized,

source§

fn span(&self) -> Span

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty.
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,