Debian Codegraph @

src/types/mod.rs

raw symbols SCIP
1 mod arc;
2 mod r#box;
3 mod cow;
4 mod r#mut;
5 mod rc;
6 mod r#ref;
7
8 // ---------------------------------------------------------------------------
9
10 #[derive(Debug, PartialEq, Eq, Hash)]
11 pub enum Type {
12 Box,
13 Cow,
14 Ref,
15 Mut,
16 Rc,
17 Arc,
18 }
19
20 impl Type {
21 pub fn from_str(s: &str) -> Option<Self> {
22 match s {
23 "Box" => Some(Type::Box),
24 "Cow" => Some(Type::Cow),
25 "Ref" => Some(Type::Ref),
26 "Mut" => Some(Type::Mut),
27 "Rc" => Some(Type::Rc),
28 "Arc" => Some(Type::Arc),
29 _ => None,
30 }
31 }
32
33 pub fn from_path(p: &syn::Path) -> Option<Self> {
34 p.segments
35 .first()
36 .and_then(|s| Self::from_str(&s.ident.to_string()))
37 }
38
39 pub fn defer_trait_methods(&self, trait_: &syn::ItemTrait) -> syn::Result<syn::ItemImpl> {
40 match self {
41 Type::Box => self::r#box::derive(trait_),
42 Type::Cow => self::cow::derive(trait_),
43 Type::Ref => self::r#ref::derive(trait_),
44 Type::Mut => self::r#mut::derive(trait_),
45 Type::Rc => self::rc::derive(trait_),
46 Type::Arc => self::arc::derive(trait_),
47 }
48 }
49 }