pub struct Span {
pub start: ByteIndex,
pub end: ByteIndex,
}
Expand description
A span corresponding to a range in the source file being parsed.
Fields§
§start: ByteIndex
The start of the span in bytes.
end: ByteIndex
The end of the span in bytes.
Implementations§
source§impl Span
impl Span
sourcepub fn new<S, E>(start: S, end: E) -> Span
pub fn new<S, E>(start: S, end: E) -> Span
Construct a new span.
§Examples
use rune::ast::Span;
let span = Span::new(42, 50);
assert!(span < Span::new(100, 101));
sourcepub fn point<P>(pos: P) -> Span
pub fn point<P>(pos: P) -> Span
Get a span corresponding to a single point where both start and end are the same byte offset.
§Examples
use rune::ast::Span;
assert_eq!(Span::point(42), Span::new(42, 42));
sourcepub const fn empty() -> Span
pub const fn empty() -> Span
Constant function to build an empty span.
§Examples
use rune::ast::Span;
assert_eq!(Span::empty(), Span::new(0, 0));
sourcepub fn join(self, other: Span) -> Span
pub fn join(self, other: Span) -> Span
Join two spans creating the larger of the two spans.
§Examples
use rune::ast::Span;
let a = Span::new(10, 12);
let b = Span::new(20, 22);
assert_eq!(a.join(b), Span::new(10, 22));
sourcepub fn narrow(self, amount: impl Into<ByteIndex>) -> Span
pub fn narrow(self, amount: impl Into<ByteIndex>) -> Span
Narrow the span with the given amount.
If the narrowing causes the span to become empty, the resulting span will reflect the starting point of the narrowed span.
§Examples
use rune::ast::Span;
assert_eq!(Span::new(10, 12).narrow(4), Span::new(10, 10));
assert_eq!(Span::new(5, 15).narrow(2), Span::new(7, 13));
Trait Implementations§
source§impl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
source§fn deserialize<D>(
deserializer: D
) -> Result<Span, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Span, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Span
impl Ord for Span
source§impl PartialEq for Span
impl PartialEq for Span
source§impl PartialOrd for Span
impl PartialOrd for Span
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for Span
impl Serialize for Span
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
Return the
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates
Self
using data from the given World
.