Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wiggle/generate/src/lifetimes.rs
1693 views
1
use proc_macro2::TokenStream;
2
use quote::quote;
3
4
pub trait LifetimeExt {
5
fn needs_lifetime(&self) -> bool;
6
}
7
8
impl LifetimeExt for witx::TypeRef {
9
fn needs_lifetime(&self) -> bool {
10
self.type_().needs_lifetime()
11
}
12
}
13
14
impl LifetimeExt for witx::Type {
15
fn needs_lifetime(&self) -> bool {
16
match self {
17
witx::Type::Builtin(b) => b.needs_lifetime(),
18
witx::Type::Record(s) => s.needs_lifetime(),
19
witx::Type::Variant(u) => u.needs_lifetime(),
20
witx::Type::Handle { .. } => false,
21
witx::Type::Pointer { .. }
22
| witx::Type::ConstPointer { .. }
23
| witx::Type::List { .. } => true,
24
}
25
}
26
}
27
28
impl LifetimeExt for witx::BuiltinType {
29
fn needs_lifetime(&self) -> bool {
30
false
31
}
32
}
33
34
impl LifetimeExt for witx::RecordDatatype {
35
fn needs_lifetime(&self) -> bool {
36
self.members.iter().any(|m| m.tref.needs_lifetime())
37
}
38
}
39
40
impl LifetimeExt for witx::Variant {
41
fn needs_lifetime(&self) -> bool {
42
self.cases
43
.iter()
44
.any(|m| m.tref.as_ref().map(|t| t.needs_lifetime()).unwrap_or(false))
45
}
46
}
47
48
pub fn anon_lifetime() -> TokenStream {
49
quote!('_)
50
}
51
52