pub trait Component<T>{
// 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§
Sourcefn format(&self, sb: &mut StyledBuffer<T>, errs: &mut Vec<ComponentFormatError>)
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
String can be considered as a component of diagnostic with no style.
impl<T> Component<T> for String
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.