Struct sourceannot::SourceSnippet
source · pub struct SourceSnippet { /* private fields */ }
Expand description
A snippet of source code.
Implementations§
source§impl SourceSnippet
impl SourceSnippet
sourcepub fn build_from_utf8(
start_line: usize,
source: &[u8],
tab_width: usize
) -> Self
pub fn build_from_utf8( start_line: usize, source: &[u8], tab_width: usize ) -> Self
Creates a snippet from a UTF-8 (possibly broken) source.
Each byte of ASCII control characters and invalid UTF-8 sequences is
represented as <XX>
as alternative text.
sourcepub fn build_from_utf8_ex<FnCtrl, FnInv>(
start_line: usize,
source: &[u8],
on_control: FnCtrl,
on_invalid: FnInv,
invalid_multi: bool
) -> Self
pub fn build_from_utf8_ex<FnCtrl, FnInv>( start_line: usize, source: &[u8], on_control: FnCtrl, on_invalid: FnInv, invalid_multi: bool ) -> Self
Creates a snippet from a UTF-8 (possibly broken) source.
on_control
is used to handle ASCII control characters. on_invalid
and invalid_multi
are used to handle invalid UTF-8 sequences.
When invalid_multi
is true
, on_invalid
is called for each byte
of an invalid UTF-8 sequence. Otherwise, on_invalid
is called once
with the entire sequence.
on_control
and on_invalid
also returns a boolean to indicate if
the text should be rendered alternative.
source§impl SourceSnippet
impl SourceSnippet
pub fn get_line_col(&self, pos: usize) -> (usize, usize)
Trait Implementations§
source§impl Clone for SourceSnippet
impl Clone for SourceSnippet
source§fn clone(&self) -> SourceSnippet
fn clone(&self) -> SourceSnippet
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 moreAuto Trait Implementations§
impl Freeze for SourceSnippet
impl RefUnwindSafe for SourceSnippet
impl Send for SourceSnippet
impl Sync for SourceSnippet
impl Unpin for SourceSnippet
impl UnwindSafe for SourceSnippet
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