Skip to main content

LabeledSpan

Struct LabeledSpan 

Source
pub struct LabeledSpan { /* private fields */ }
Expand description

A labeled SourceSpan.

Implementations§

Source§

impl LabeledSpan

Source

pub const fn new( label: Option<String>, offset: usize, len: usize, ) -> LabeledSpan

Makes a new labeled span.

Source

pub fn new_with_span( label: Option<String>, span: impl Into<SourceSpan>, ) -> LabeledSpan

Makes a new labeled span using an existing span.

Source

pub fn new_primary_with_span( label: Option<String>, span: impl Into<SourceSpan>, ) -> LabeledSpan

Makes a new labeled primary span using an existing span.

Source

pub fn set_label(&mut self, label: Option<String>)

Change the text of the label

Source

pub fn at(span: impl Into<SourceSpan>, label: impl Into<String>) -> LabeledSpan

Makes a new label at specified span

§Examples
use miette::LabeledSpan;

let source = "Cpp is the best";
let label = LabeledSpan::at(0..3, "should be Rust");
assert_eq!(
    label,
    LabeledSpan::new(Some("should be Rust".to_string()), 0, 3)
)
Source

pub fn at_offset(offset: usize, label: impl Into<String>) -> LabeledSpan

Makes a new label that points at a specific offset.

§Examples
use miette::LabeledSpan;

let source = "(2 + 2";
let label = LabeledSpan::at_offset(4, "expected a closing parenthesis");
assert_eq!(
    label,
    LabeledSpan::new(Some("expected a closing parenthesis".to_string()), 4, 0)
)
Source

pub fn underline(span: impl Into<SourceSpan>) -> LabeledSpan

Makes a new label without text, that underlines a specific span.

§Examples
use miette::LabeledSpan;

let source = "You have an eror here";
let label = LabeledSpan::underline(12..16);
assert_eq!(label, LabeledSpan::new(None, 12, 4))
Source

pub fn label(&self) -> Option<&str>

Gets the (optional) label string for this LabeledSpan.

Source

pub const fn inner(&self) -> &SourceSpan

Returns a reference to the inner SourceSpan.

Source

pub const fn offset(&self) -> usize

Returns the 0-based starting byte offset.

Source

pub const fn len(&self) -> usize

Returns the number of bytes this LabeledSpan spans.

Source

pub const fn is_empty(&self) -> bool

True if this LabeledSpan is empty.

Source

pub const fn primary(&self) -> bool

True if this LabeledSpan is a primary span.

Trait Implementations§

Source§

impl Clone for LabeledSpan

Source§

fn clone(&self) -> LabeledSpan

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LabeledSpan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for LabeledSpan

Source§

impl From<Label> for LabeledSpan

Source§

fn from(label: Label) -> LabeledSpan

Converts to this type from the input type.
Source§

impl PartialEq for LabeledSpan

Source§

fn eq(&self, other: &LabeledSpan) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for LabeledSpan

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.