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
//! Trait used for custom element.

use crate::{Config, Formatter, Tokens};
use std::fmt;

/// Trait that must be implemented by custom elements.
pub trait Custom
where
    Self: Sized,
{
    /// Configuration associated with building a formatting element.
    type Config: Config;

    /// Format the custom element.
    fn format(
        &self,
        _out: &mut Formatter,
        _config: &mut Self::Config,
        _level: usize,
    ) -> fmt::Result {
        Ok(())
    }

    /// Performing quoting according to convention set by custom element.
    fn quote_string(out: &mut Formatter, input: &str) -> fmt::Result {
        out.write_str(input)
    }

    /// Write a file according to convention by custom element.
    fn write_file<'el>(
        tokens: Tokens<'el, Self>,
        out: &mut Formatter,
        config: &mut Self::Config,
        level: usize,
    ) -> fmt::Result {
        tokens.format(out, config, level)
    }
}

/// Dummy implementation for unit.
impl Custom for () {
    type Config = ();
}