[][src]Struct asciifile::span::Span

pub struct Span<'f> { /* fields omitted */ }

Methods

impl<'f> Span<'f>
[src]

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());

Important traits for LineIterator<'span, 'file>

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

Trait Implementations

impl<'f> PartialEq<Span<'f>> for Span<'f>
[src]

impl<'f> Clone for Span<'f>
[src]

Performs copy-assignment from source. Read more

impl<'f> Copy for Span<'f>
[src]

impl<'f> Eq for Span<'f>
[src]

impl<'_> Display for Span<'_>
[src]

impl<'f> Debug for Span<'f>
[src]

Auto Trait Implementations

impl<'f> Send for Span<'f>

impl<'f> Sync for Span<'f>

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]