Trait Component

Source
pub trait Component<T>
where T: Clone + PartialEq + Eq + Style,
{ // Required method fn format( &self, sb: &mut StyledBuffer<T>, errs: &mut Vec<ComponentFormatError>, ); }
Expand description

‘Component’ specifies the method format() that all diagnostic components should implement.

‘Component’ decouples ‘structure’ and ‘theme’ during formatting diagnostic components. T: Clone + PartialEq + Eq + Style is responsible for ‘theme’ such as colors/fonts in the component formatting. format() organizes the ‘structure’ of diagnostic components.

Required Methods§

Source

fn format(&self, sb: &mut StyledBuffer<T>, errs: &mut Vec<ComponentFormatError>)

format() formats components into StyledString and saves them in StyledBuffer.

§Examples

struct ComponentWithStyleLogo {
    text: String
}

impl Component<DiagnosticStyle> for ComponentWithStyleLogo {
    fn format(&self, sb: &mut StyledBuffer<DiagnosticStyle>, errs: &mut Vec<ComponentFormatError>) {
        // set style
        sb.pushs(&self.text, Some(DiagnosticStyle::Logo));
    }
}

Implementations on Foreign Types§

Source§

impl<T> Component<T> for String
where T: Clone + PartialEq + Eq + Style + Debug,

String can be considered as a component of diagnostic with no style.

The result of component String rendering is a String who has no style.

Source§

fn format(&self, sb: &mut StyledBuffer<T>, _: &mut Vec<ComponentFormatError>)

Implementors§