aboutsummaryrefslogtreecommitdiff
path: root/syn/codegen/src/operand.rs
blob: db3bd18711050340e3c07bd83069a31c937c5e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use proc_macro2::TokenStream;
use quote::quote;

pub enum Operand {
    Borrowed(TokenStream),
    Owned(TokenStream),
}

pub use self::Operand::*;

impl Operand {
    pub fn tokens(&self) -> &TokenStream {
        match self {
            Borrowed(n) | Owned(n) => n,
        }
    }

    pub fn ref_tokens(&self) -> TokenStream {
        match self {
            Borrowed(n) => n.clone(),
            Owned(n) => quote!(&#n),
        }
    }

    pub fn ref_mut_tokens(&self) -> TokenStream {
        match self {
            Borrowed(n) => n.clone(),
            Owned(n) => quote!(&mut #n),
        }
    }

    pub fn owned_tokens(&self) -> TokenStream {
        match self {
            Borrowed(n) => quote!(*#n),
            Owned(n) => n.clone(),
        }
    }
}