Path: blob/main/crates/wiggle/generate/src/lifetimes.rs
1693 views
use proc_macro2::TokenStream;1use quote::quote;23pub trait LifetimeExt {4fn needs_lifetime(&self) -> bool;5}67impl LifetimeExt for witx::TypeRef {8fn needs_lifetime(&self) -> bool {9self.type_().needs_lifetime()10}11}1213impl LifetimeExt for witx::Type {14fn needs_lifetime(&self) -> bool {15match self {16witx::Type::Builtin(b) => b.needs_lifetime(),17witx::Type::Record(s) => s.needs_lifetime(),18witx::Type::Variant(u) => u.needs_lifetime(),19witx::Type::Handle { .. } => false,20witx::Type::Pointer { .. }21| witx::Type::ConstPointer { .. }22| witx::Type::List { .. } => true,23}24}25}2627impl LifetimeExt for witx::BuiltinType {28fn needs_lifetime(&self) -> bool {29false30}31}3233impl LifetimeExt for witx::RecordDatatype {34fn needs_lifetime(&self) -> bool {35self.members.iter().any(|m| m.tref.needs_lifetime())36}37}3839impl LifetimeExt for witx::Variant {40fn needs_lifetime(&self) -> bool {41self.cases42.iter()43.any(|m| m.tref.as_ref().map(|t| t.needs_lifetime()).unwrap_or(false))44}45}4647pub fn anon_lifetime() -> TokenStream {48quote!('_)49}505152