Merge pull request #290 from brendanzab/files-docs

improve documentation in the files module
This commit is contained in:
Brendan Zabarauskas 2020-09-20 18:34:43 +10:00 committed by GitHub
commit 86ec1a5c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@
//! Simple implementations of this trait are implemented:
//!
//! - [`SimpleFile`]: For single-file use-cases
//! - [`SimpleFiles`]: For single-file use-cases
//! - [`SimpleFiles`]: For multi-file use-cases
//!
//! These data structures provide a pretty minimal API, however,
//! so end-users are encouraged to create their own implementations for their
@ -46,6 +46,8 @@ pub trait Files<'a> {
fn source(&'a self, id: Self::FileId) -> Option<Self::Source>;
/// The index of the line at the given byte index.
/// If the byte index is past the end of the file, returns the maximum line index in the file.
/// This means that this function only fails if the file is not present.
///
/// # Note for trait implementors
///
@ -59,6 +61,8 @@ pub trait Files<'a> {
fn line_index(&'a self, id: Self::FileId, byte_index: usize) -> Option<usize>;
/// The user-facing line number at the given line index.
/// It is not necessarily checked that the specified line index
/// is actually in the file.
///
/// # Note for trait implementors
///
@ -285,6 +289,7 @@ where
///
/// This is useful for simple language tests, but it might be worth creating a
/// custom implementation when a language scales beyond a certain size.
/// It is a glorified `Vec<SimpleFile>` that implements the `Files` trait.
#[derive(Debug, Clone)]
pub struct SimpleFiles<Name, Source> {
files: Vec<SimpleFile<Name, Source>>,