pub struct Span<'f> { /* fields omitted */ }
Create a new span from two positions.
This is guranteed to return a valid range. If the order of the
arguments is incorrect, they will be swapped. If the same position
is given twice, the span will cover a single character, the character
given by the position,
Creates a span containing only the given position
use asciifile::{AsciiFile, Position, Span};
let file = AsciiFile::new(b"ABCD").unwrap();
let position = file.iter().nth(2).unwrap();
let span = Span::from_single_position(position);
assert_eq!("C", span.as_str());
Creates a span containing only the given position
use asciifile::{AsciiFile, Position, Span};
let file = AsciiFile::new(b"abcdfeghAAA").unwrap();
let positions = file
.iter()
.take_while(|position| position.chr().is_lowercase())
.collect::<Vec<_>>();
let span = Span::from_positions(&positions).unwrap();
assert_eq!("abcdfegh", span.as_str());
Check if a span extends over multiple lines
This will not consider spans that contain a single trailing
whitespace as multiline.
use asciifile::{AsciiFile, Span};
let file = AsciiFile::new("a\n".as_bytes()).unwrap();
let first = file.iter().next().unwrap();
let last = file.iter().last().unwrap();
let span = Span::new(first, last);
assert!(!span.is_multiline());
Also, A span only containing a newline will not be considered
multiline.
use asciifile::{AsciiFile, Span};
let file = AsciiFile::new("\n".as_bytes()).unwrap();
let newline = file.iter().next().unwrap();
let span = Span::new(newline, newline);
assert!(!span.is_multiline());
A span with one or more newlines as a prefix will be considered
multiline.
use asciifile::{AsciiFile, Span};
let file = AsciiFile::new("\na".as_bytes()).unwrap();
let first = file.iter().next().unwrap();
let last = file.iter().last().unwrap();
let span = Span::new(first, last);
assert!(span.is_multiline());
An iterator over the lines of a span.
extends the span to include the given position
test if a span contains another span
Get the overlapping part of two spans.
Returns None
if the spans are disjunct (do not overlap).
Get the number of characters in a span
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String
. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static