Add Span::{line, column}
This commit is contained in:
parent
87ec0738ab
commit
a1cd8c3a28
4 changed files with 38 additions and 0 deletions
|
@ -97,6 +97,8 @@ macro_rules! with_api {
|
|||
fn byte_range($self: $S::Span) -> Range<usize>;
|
||||
fn start($self: $S::Span) -> $S::Span;
|
||||
fn end($self: $S::Span) -> $S::Span;
|
||||
fn line($self: $S::Span) -> usize;
|
||||
fn column($self: $S::Span) -> usize;
|
||||
fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
|
||||
fn subspan($self: $S::Span, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
|
||||
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
|
||||
|
|
|
@ -505,6 +505,22 @@ impl Span {
|
|||
Span(self.0.end())
|
||||
}
|
||||
|
||||
/// The one-indexed line of the source file where the span starts.
|
||||
///
|
||||
/// To obtain the line of the span's end, use `span.end().line()`.
|
||||
#[unstable(feature = "proc_macro_span", issue = "54725")]
|
||||
pub fn line(&self) -> usize {
|
||||
self.0.line()
|
||||
}
|
||||
|
||||
/// The one-indexed column of the source file where the span starts.
|
||||
///
|
||||
/// To obtain the column of the span's end, use `span.end().column()`.
|
||||
#[unstable(feature = "proc_macro_span", issue = "54725")]
|
||||
pub fn column(&self) -> usize {
|
||||
self.0.column()
|
||||
}
|
||||
|
||||
/// Creates a new span encompassing `self` and `other`.
|
||||
///
|
||||
/// Returns `None` if `self` and `other` are from different files.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue