Skip to main content

SourceCode

Trait SourceCode 

Source
pub trait SourceCode: Send + Sync {
    // Required method
    fn read_span<'a>(
        &'a self,
        span: &SourceSpan,
        context_lines_before: usize,
        context_lines_after: usize,
    ) -> Result<MietteSpanContents<'a>, MietteError>;

    // Provided method
    fn name(&self) -> Option<&str> { ... }
}
Expand description

Represents readable source code of some sort.

This trait is able to support simple SourceCode types like Strings, as well as more involved types like indexes into centralized SourceMap-like types, file handles, and even network streams.

If you can read it, you can source it, and it’s not necessary to read the whole thing–meaning you should be able to support SourceCodes which are gigabytes or larger in size.

Required Methods§

Source

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Read the bytes for a specific span from this SourceCode, keeping a certain number of lines before and after the span as context.

Provided Methods§

Source

fn name(&self) -> Option<&str>

Returns the name of this source code, if any.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl SourceCode for &[u8]

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

impl SourceCode for &str

Makes src: &'static str or struct S<'a> { src: &'a str } usable.

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

impl SourceCode for String

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

impl SourceCode for Vec<u8>

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

impl SourceCode for [u8]

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

impl SourceCode for str

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

impl<T: ?Sized + SourceCode + ToOwned> SourceCode for Cow<'_, T>
where T::Owned: Debug + Send + Sync,

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

fn name(&self) -> Option<&str>

Source§

impl<T: ?Sized + SourceCode> SourceCode for Arc<T>

Source§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<MietteSpanContents<'a>, MietteError>

Source§

fn name(&self) -> Option<&str>

Implementors§

Source§

impl<S: SourceCode + 'static> SourceCode for NamedSource<S>