swc_html_codegen/
emit.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::fmt::Result;

use swc_common::Spanned;

///
/// # Type parameters
///
/// ## `T`
///
/// The type of the ast node.
pub trait Emit<T>
where
    T: Spanned,
{
    fn emit(&mut self, node: &T) -> Result;
}

impl<T, E> Emit<&'_ T> for E
where
    E: Emit<T>,
    T: Spanned,
{
    #[allow(clippy::only_used_in_recursion)]
    #[inline]
    fn emit(&mut self, node: &&'_ T) -> Result {
        self.emit(&**node)
    }
}

impl<T, E> Emit<Box<T>> for E
where
    E: Emit<T>,
    T: Spanned,
{
    #[inline]
    fn emit(&mut self, node: &Box<T>) -> Result {
        self.emit(&**node)
    }
}

impl<T, E> Emit<Option<T>> for E
where
    E: Emit<T>,
    T: Spanned,
{
    #[inline]
    fn emit(&mut self, node: &Option<T>) -> Result {
        match node {
            Some(node) => self.emit(node),
            None => Ok(()),
        }
    }
}