Skip to main content

SourceCode

Trait SourceCode 

pub trait SourceCode: Send + Sync {
    // Required method
    fn read_span<'a>(
        &'a self,
        span: &SourceSpan,
        context_lines_before: usize,
        context_lines_after: usize,
    ) -> Result<Box<dyn SpanContents<'a> + 'a>, MietteError>;
}
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§

fn read_span<'a>( &'a self, span: &SourceSpan, context_lines_before: usize, context_lines_after: usize, ) -> Result<Box<dyn SpanContents<'a> + '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.

Implementations on Foreign Types§

§

impl SourceCode for str

§

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

§

impl SourceCode for String

§

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

§

impl SourceCode for Vec<u8>

§

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

§

impl SourceCode for SourceFile

§

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

§

impl SourceCode for SourceFileRef

§

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

§

impl SourceCode for [u8]

§

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

§

impl<'s> SourceCode for &'s str

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

§

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

§

impl<'src> SourceCode for &'src [u8]

§

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

§

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

§

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

§

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

§

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

Implementors§

§

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