oxc/tasks/ast_tools/src/schema/get_generics.rs
rzvxa 8e8fcd0584 refactor(ast_tools): rename oxc_ast_codegen to oxc_ast_tools. (#4846)
This PR renames the `oxc_ast_codegen` crate to `oxc_ast_tools`, It improves the readability and organization of the codebase by giving the crate a name that better reflects its purpose and contents.

It also improves the error message in CI.
2024-08-12 14:33:58 +00:00

38 lines
689 B
Rust

use syn::parse_quote;
use super::{
defs::{EnumDef, StructDef, TypeDef},
with_either,
};
pub trait GetGenerics {
fn has_lifetime(&self) -> bool {
false
}
fn generics(&self) -> Option<syn::Generics> {
if self.has_lifetime() {
Some(parse_quote!(<'a>))
} else {
None
}
}
}
impl GetGenerics for TypeDef {
fn has_lifetime(&self) -> bool {
with_either!(self, it => it.has_lifetime())
}
}
impl GetGenerics for StructDef {
fn has_lifetime(&self) -> bool {
self.has_lifetime
}
}
impl GetGenerics for EnumDef {
fn has_lifetime(&self) -> bool {
self.has_lifetime
}
}