pub struct EmptySpan { /* private fields */ }Available on crate feature
span only.Expand description
Newtype of Span::len() == 0
Methods from Deref<Target = Span>§
Sourcepub fn create(&self, range: TextRange) -> Self
pub fn create(&self, range: TextRange) -> Self
New a span source range from exist span.
§Panics
- Panics if
rangeout of source.
§Examples
use line_column::span::*;
let source = "abcdef";
let full = Span::new_full(source);
assert_eq!(full.text(), "abcdef");
let span = full.create(TextRange::at(1.into(), 3.into()));
assert_eq!(span.text(), "bcd");
let span2 = span.create(TextRange::at(3.into(), 3.into()));
assert_eq!(span2.text(), "def");Sourcepub fn slice(&self, range: TextRange) -> Self
pub fn slice(&self, range: TextRange) -> Self
New a span relative range from exist span.
§Panics
- Panics if
range+startout of source.
§Examples
use line_column::span::*;
let source = "abcdef";
let full = Span::new_full(source);
assert_eq!(full.text(), "abcdef");
let span = full.slice(TextRange::at(1.into(), 3.into()));
assert_eq!(span.text(), "bcd");
let span2 = span.slice(TextRange::at(1.into(), 3.into()));
assert_eq!(span2.text(), "cde");Sourcepub fn split(&self, len: TextSize) -> (Self, Self)
pub fn split(&self, len: TextSize) -> (Self, Self)
New splited span pair relative range from exist span.
§Panics
- Panics if
range+atout of source.
§Examples
use line_column::span::*;
let source = "abcdef";
let full = Span::new_full(source);
assert_eq!(full.text(), "abcdef");
let (a, span) = full.split(TextSize::of("a"));
assert_eq!(a.text(), "a");
assert_eq!(span.text(), "bcdef");
let (bcd, span2) = span.split(TextSize::of("bcd"));
assert_eq!(bcd.text(), "bcd");
assert_eq!(span2.text(), "ef");Sourcepub fn take(&self, len: TextSize) -> Self
pub fn take(&self, len: TextSize) -> Self
Returns truncated sub-span.
§Examples
use line_column::span::*;
let span = Span::new("foobarbaz", TextRange::new(3.into(), 7.into()));
assert_eq!(span.text(), "barb");
assert_eq!(span.take(3.into()).text(), "bar");Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Returns the source text of the range reference.
§Examples
use line_column::span::*;
let span = Span::new("abcdef", TextRange::new(1.into(), 4.into()));
assert_eq!(span.text(), "bcd");Sourcepub fn range(&self) -> TextRange
pub fn range(&self) -> TextRange
Returns the source text of the range reference.
§Examples
use line_column::span::*;
let span = Span::new("abcdef", TextRange::new(1.into(), 4.into()));
assert_eq!(span.range(), TextRange::new(1.into(), 4.into()));Sourcepub fn source(&self) -> &str
pub fn source(&self) -> &str
Returns the source text.
§Examples
use line_column::span::*;
let span = Span::new("abcdef", TextRange::new(1.into(), 4.into()));
assert_eq!(span.source(), "abcdef");
assert_eq!(span.text(), "bcd");pub fn line_column(&self) -> (u32, u32)
pub fn line(&self) -> u32
pub fn column(&self) -> u32
Sourcepub fn current_line(&self) -> Self
pub fn current_line(&self) -> Self
Returns the current line of this Span.
Maybe include end of line char, like '\n'.
§Examples
use line_column::span::*;
let span = Span::new_full("foo\nbar\nbaz");
let next = span.create(TextRange::at(TextSize::of("foo\n"), 5.into()));
let tail = span.create(TextRange::at(TextSize::of("foo\nbar\n"), 3.into()));
let endl = span.create(TextRange::at(TextSize::of("foo"), 3.into()));
assert_eq!(next.text(), "bar\nb");
assert_eq!(tail.text(), "baz");
assert_eq!(endl.text(), "\nba");
assert_eq!(span.current_line().text(), "foo\n");
assert_eq!(next.current_line().text(), "bar\n");
assert_eq!(tail.current_line().text(), "baz");
assert_eq!(endl.current_line().text(), "foo\n");Sourcepub fn prev_line(&self) -> Self
pub fn prev_line(&self) -> Self
Returns the previous line of this Span.
§Examples
use line_column::span::*;
let span = Span::new_full("foo\nbar\nbaz");
let next = span.create(TextRange::at(TextSize::of("foo\n"), 5.into()));
let tail = span.create(TextRange::at(TextSize::of("foo\nbar\n"), 3.into()));
let endl = span.create(TextRange::at(TextSize::of("foo"), 3.into()));
assert_eq!(next.text(), "bar\nb");
assert_eq!(tail.text(), "baz");
assert_eq!(endl.text(), "\nba");
assert_eq!(span.prev_line().text(), "");
assert_eq!(next.prev_line().text(), "foo\n");
assert_eq!(tail.prev_line().text(), "bar\n");
assert_eq!(endl.prev_line().text(), "");Sourcepub fn next_line(&self) -> Self
pub fn next_line(&self) -> Self
Returns the next line of this Span.
§Examples
use line_column::span::*;
let span = Span::new_full("foo\nbar\nbaz");
let next = span.create(TextRange::at(TextSize::of("foo\n"), 5.into()));
let tail = span.create(TextRange::at(TextSize::of("foo\nbar\n"), 3.into()));
let endl = span.create(TextRange::at(TextSize::of("foo"), 3.into()));
assert_eq!(next.text(), "bar\nb");
assert_eq!(tail.text(), "baz");
assert_eq!(endl.text(), "\nba");
assert_eq!(span.next_line().text(), "bar\n");
assert_eq!(next.next_line().text(), "baz");
assert_eq!(tail.next_line().text(), "");
assert_eq!(endl.next_line().text(), "bar\n");Sourcepub fn trim_start(&self) -> Self
pub fn trim_start(&self) -> Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EmptySpan
impl RefUnwindSafe for EmptySpan
impl Send for EmptySpan
impl Sync for EmptySpan
impl Unpin for EmptySpan
impl UnwindSafe for EmptySpan
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more