#file-line #line-column #string #processing #api #information #spans

spanned

string processing with file/line/col information and the regular rust str API

7 releases

0.1.6 Feb 27, 2024
0.1.5 Nov 13, 2023
0.1.3 Oct 22, 2023

#647 in Filesystem

Download history 85/week @ 2024-01-20 814/week @ 2024-01-27 1581/week @ 2024-02-03 968/week @ 2024-02-10 2253/week @ 2024-02-17 3720/week @ 2024-02-24 5574/week @ 2024-03-02 6025/week @ 2024-03-09 4257/week @ 2024-03-16 4157/week @ 2024-03-23 4277/week @ 2024-03-30 3386/week @ 2024-04-06

17,092 downloads per month
Used in 2 crates (via ui_test)

MIT/Apache

11KB
277 lines

Simple span handling for str and &[u8]

This crate exposes some of the methods that exist on str or bstr. If you are missing any you need, please open issues or PRs.

The basic usage is to read from a file and then use the methods to modify it:

let file = Spanned<String>::read_from_file(path)?;
for line in file.lines() {
    if let Some(rest) = line.strip_prefix("cake:") {
        println!("found a cake at {}: {}", rest.span.line_start, *rest);
    }
}

any Spanned object will always know its file, line and column information and correctly preserve it across operations that take subslices. The column information is counted in the number of utf8 characters, which is not entirely correct. Please open an issue if you encounter this to be a problem.

Dependencies

~5MB
~84K SLoC