musli_macros/internals/
expansion.rs

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
use crate::internals::tokens::Tokens;
use crate::internals::{Mode, Only};

use super::attr::{ModeIdent, ModeKind};
use super::mode::ModePath;

#[derive(Clone, Copy)]
pub(crate) struct Expansion<'a> {
    pub(crate) mode_ident: &'a ModeIdent,
}

impl<'a> Expansion<'a> {
    pub(crate) fn as_mode(&'a self, tokens: &'a Tokens, only: Only) -> Mode<'a> {
        Mode {
            kind: Some(&self.mode_ident.kind),
            mode_path: self.mode_path(tokens),
            tokens,
            only,
        }
    }

    pub(crate) fn mode_path(&self, tokens: &'a Tokens) -> ModePath<'a> {
        match &self.mode_ident.kind {
            ModeKind::Custom(..) => ModePath::Ident(&self.mode_ident.ident),
            _ => ModePath::Musli(&tokens.prefix, &self.mode_ident.ident),
        }
    }
}