/// A spanned value, indicating the range at which it is defined in the source. /// /// ``` /// use serde_derive::Deserialize; /// use toml::Spanned; /// /// #[derive(Deserialize)] /// struct Value { /// s: Spanned<String>, /// } /// /// let t = "s = \"value\"\n"; /// /// let u: Value = toml::from_str(t).unwrap(); /// /// assert_eq!(u.s.start(), 4); /// assert_eq!(u.s.end(), 11); /// assert_eq!(u.s.get_ref(), "value"); /// assert_eq!(u.s.into_inner(), String::from("value")); /// ``` #[derive(Clone, Debug)] pubstruct Spanned<T> { /// The start range.
start: usize, /// The end range (exclusive).
end: usize, /// The spanned value.
value: T,
}
impl<T> Spanned<T> { /// Access the start of the span of the contained value. pubfn start(&self) -> usize { self.start
}
/// Access the end of the span of the contained value. pubfn end(&self) -> usize { self.end
}
/// Get the span of the contained value. pubfn span(&self) -> (usize, usize) {
(self.start, self.end)
}
/// Consumes the spanned value and returns the contained value. pubfn into_inner(self) -> T { self.value
}
/// Returns a reference to the contained value. pubfn get_ref(&self) -> &T {
&self.value
}
/// Returns a mutable reference to the contained value. pubfn get_mut(&mutself) -> &mut T {
&mutself.value
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.