pub struct Spanned<T> { /* private fields */ }
Expand description
A spanned value, indicating the range at which it is defined in the source.
Implementations§
Source§impl<T> Spanned<T>
impl<T> Spanned<T>
Sourcepub fn new(range: Range<usize>, value: T) -> Spanned<T>
pub fn new(range: Range<usize>, value: T) -> Spanned<T>
Create a spanned value encompassing the given byte range.
§Example
Transposing a Spanned<Enum<T>>
into Enum<Spanned<T>>
:
use serde::de::{Deserialize, Deserializer};
use serde_untagged::UntaggedEnumVisitor;
use toml::Spanned;
pub enum Dependency {
Simple(Spanned<String>),
Detailed(Spanned<DetailedDependency>),
}
impl<'de> Deserialize<'de> for Dependency {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
enum DependencyKind {
Simple(String),
Detailed(DetailedDependency),
}
impl<'de> Deserialize<'de> for DependencyKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
UntaggedEnumVisitor::new()
.expecting(
"a version string like \"0.9.8\" or a \
detailed dependency like { version = \"0.9.8\" }",
)
.string(|value| Ok(DependencyKind::Simple(value.to_owned())))
.map(|value| value.deserialize().map(DependencyKind::Detailed))
.deserialize(deserializer)
}
}
let spanned: Spanned<DependencyKind> = Deserialize::deserialize(deserializer)?;
let range = spanned.span();
Ok(match spanned.into_inner() {
DependencyKind::Simple(simple) => Dependency::Simple(Spanned::new(range, simple)),
DependencyKind::Detailed(detailed) => Dependency::Detailed(Spanned::new(range, detailed)),
})
}
}
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the spanned value and returns the contained value.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Spanned<T>where
T: Deserialize<'de>,
Available on crate feature serde
only.
impl<'de, T> Deserialize<'de> for Spanned<T>where
T: Deserialize<'de>,
Available on crate feature
serde
only.Source§fn deserialize<D>(
deserializer: D,
) -> Result<Spanned<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Spanned<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> Ord for Spanned<T>where
T: Ord,
impl<T> Ord for Spanned<T>where
T: Ord,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T> PartialOrd for Spanned<T>where
T: PartialOrd,
impl<T> PartialOrd for Spanned<T>where
T: PartialOrd,
Source§impl<T> Serialize for Spanned<T>where
T: Serialize,
Available on crate feature serde
only.
impl<T> Serialize for Spanned<T>where
T: Serialize,
Available on crate feature
serde
only.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<T> Eq for Spanned<T>where
T: Eq,
Auto Trait Implementations§
impl<T> Freeze for Spanned<T>where
T: Freeze,
impl<T> RefUnwindSafe for Spanned<T>where
T: RefUnwindSafe,
impl<T> Send for Spanned<T>where
T: Send,
impl<T> Sync for Spanned<T>where
T: Sync,
impl<T> Unpin for Spanned<T>where
T: Unpin,
impl<T> UnwindSafe for Spanned<T>where
T: UnwindSafe,
Blanket Implementations§
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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.impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.