pub struct Snippet<'a> {
pub code: &'a Code,
pub spans: Vec<Span<'a>>,
/* private fields */
}Expand description
Fragment of source code with annotated spans highlighting specific regions
A snippet corresponds to a single source Code. It contains
zero or more Spans that annotate specific parts of the code.
Snippet holds a Ref to the string held in self.code.value, which
provides an access to the string without making a new borrow
(code_string). This allows creating another
message builder such as annotate_snippets::Snippet without the need to
retain a borrow of self.code.value.
Fields§
§code: &'a CodeSource code to which the spans refer
spans: Vec<Span<'a>>Spans describing parts of the code
Implementations§
Source§impl Snippet<'_>
impl Snippet<'_>
Sourcepub fn with_code(code: &Code) -> Snippet<'_>
pub fn with_code(code: &Code) -> Snippet<'_>
Creates a new snippet for the given code without any spans.
Sourcepub fn with_code_and_spans<'a>(
code: &'a Code,
spans: Vec<Span<'a>>,
) -> Snippet<'a>
pub fn with_code_and_spans<'a>( code: &'a Code, spans: Vec<Span<'a>>, ) -> Snippet<'a>
Creates a new snippet for the given code with the given spans.
Sourcepub fn with_primary_span<'a>(
location: &'a Location,
label: Cow<'a, str>,
) -> Vec<Snippet<'a>>
pub fn with_primary_span<'a>( location: &'a Location, label: Cow<'a, str>, ) -> Vec<Snippet<'a>>
Creates a vector containing a snippet with a primary span.
This is a convenience function for creating a vector of snippets
containing a primary span created from the given location and label.
The returned vector can be used as the snippets field of a
Report.
This function calls
Source::extend_with_context for
location.code.source, thereby adding supplementary spans describing the
context of the source code. This means that the returned vector may
contain multiple snippets or spans if the source has a related location.
Sourcepub fn code_string(&self) -> &str
pub fn code_string(&self) -> &str
Returns the string held in self.code.value.
This method returns a reference to the string held in self.code.value.
Snippet internally holds a Ref to the string, which provides an
access to the string without making a new borrow.
Trait Implementations§
impl Eq for Snippet<'_>
Auto Trait Implementations§
impl<'a> Freeze for Snippet<'a>
impl<'a> !RefUnwindSafe for Snippet<'a>
impl<'a> !Send for Snippet<'a>
impl<'a> !Sync for Snippet<'a>
impl<'a> Unpin for Snippet<'a>
impl<'a> !UnwindSafe for Snippet<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more