difftreelog
feat Spanned::{map,as_ref}
in: master
1 file changed
crates/jrsonnet-ir/src/expr.rsdiffbeforeafterboth1use std::{1use std::{2 fmt::{self, Debug, Display},2 fmt::{self, Debug, Display},3 ops::Deref,3 ops::{Deref, RangeInclusive},4 rc::Rc,4 rc::Rc,5};5};66465 pub fn belongs_to(&self, other: &Span) -> bool {465 pub fn belongs_to(&self, other: &Span) -> bool {466 other.0 == self.0 && other.1 <= self.1 && other.2 >= self.2466 other.0 == self.0 && other.1 <= self.1 && other.2 >= self.2467 }467 }468 pub fn range(&self) -> RangeInclusive<usize> {469 let start = self.1;470 let mut end = self.2;471 if end > start {472 // Because it is originally exclusive473 end -= 1;474 }475 start as usize..=end as usize476 }468}477}469478470#[cfg(target_pointer_width = "64")]479#[cfg(target_pointer_width = "64")]492 pub fn new(value: T, span: Span) -> Self {501 pub fn new(value: T, span: Span) -> Self {493 Self { value, span }502 Self { value, span }494 }503 }504 pub fn map<U: Acyclic>(self, v: impl FnOnce(T) -> U) -> Spanned<U> {505 Spanned {506 span: self.span,507 value: v(self.value),508 }509 }510 pub fn as_ref<'a>(&'a self) -> Spanned<&'a T>511 where512 &'a T: Acyclic,513 {514 Spanned {515 span: self.span.clone(),516 value: &self.value,517 }518 }495}519}496520497impl<T: Debug + Acyclic> Debug for Spanned<T> {521impl<T: Debug + Acyclic> Debug for Spanned<T> {