pub struct Annotation {
pub header: Option<String>,
pub text: Option<String>,
pub severity: Severity,
/* private fields */
}
Expand description
Info about annotation. You can create these manually
and then pass to AnnotationList::add
or just use AnnotationList
s helper methods
Fields§
§header: Option<String>
header
will be shown above error message
text: Option<String>
text
will be shown near annotated fragment.
Note that fragment will be highlighted even if text
is None
.
To disable this, pass a zero length range when creating the annotation.
severity: Severity
Implementations§
Source§impl Annotation
impl Annotation
Sourcepub fn new(
range: Range<usize>,
severity: Severity,
header: impl AnnotationText,
text: impl AnnotationText,
) -> Result<Self>
pub fn new( range: Range<usize>, severity: Severity, header: impl AnnotationText, text: impl AnnotationText, ) -> Result<Self>
Create new annotation.
Will return Error::InvalidRange
if provided range has start > end
.
You can pass &str
, String
or Option<String>
as header and text arguments.
assert_eq!(
Annotation::new(0..5, Severity::Info, "header", "text").unwrap(),
Annotation::new(
0..5, Severity::Info, Some("header".into()), Some("text".into())
).unwrap()
);
assert!(Annotation::new(0..5, Severity::Warning, None, None).is_ok());
assert_eq!(
Annotation::new(5..0, Severity::Info, "h", "t"), Err(Error::InvalidRange(5, 0))
);
Sourcepub fn info(
range: Range<usize>,
header: impl AnnotationText,
text: impl AnnotationText,
) -> Result<Self>
pub fn info( range: Range<usize>, header: impl AnnotationText, text: impl AnnotationText, ) -> Result<Self>
Create a new Severity::Info
annotation
Sourcepub fn warning(
range: Range<usize>,
header: impl AnnotationText,
text: impl AnnotationText,
) -> Result<Self>
pub fn warning( range: Range<usize>, header: impl AnnotationText, text: impl AnnotationText, ) -> Result<Self>
Create a new Severity::Warning
annotation
Sourcepub fn error(
range: Range<usize>,
header: impl AnnotationText,
text: impl AnnotationText,
) -> Result<Self>
pub fn error( range: Range<usize>, header: impl AnnotationText, text: impl AnnotationText, ) -> Result<Self>
Create a new Severity::Error
annotation
Trait Implementations§
Source§impl Clone for Annotation
impl Clone for Annotation
Source§fn clone(&self) -> Annotation
fn clone(&self) -> Annotation
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Annotation
impl Debug for Annotation
Source§impl PartialEq for Annotation
impl PartialEq for Annotation
impl Eq for Annotation
impl StructuralPartialEq for Annotation
Auto Trait Implementations§
impl Freeze for Annotation
impl RefUnwindSafe for Annotation
impl Send for Annotation
impl Sync for Annotation
impl Unpin for Annotation
impl UnwindSafe for Annotation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more