Owned destructors

This commit is contained in:
Tony Garnock-Jones 2021-09-11 02:47:51 +02:00
parent 4afc6d4c94
commit eda9979041
1 changed files with 32 additions and 0 deletions

View File

@ -737,6 +737,13 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
}
}
pub fn into_record(self) -> Option<Record<N>> {
match self {
Value::Record(r) => Some(r),
_ => None,
}
}
pub fn as_record_mut(&mut self, arity: Option<usize>) -> Option<&mut Record<N>> {
if let Value::Record(r) = self {
match arity {
@ -809,6 +816,13 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
}
}
pub fn into_sequence(self) -> Option<Vec<N>> {
match self {
Value::Sequence(s) => Some(s),
_ => None,
}
}
pub fn as_sequence_mut(&mut self) -> Option<&mut Vec<N>> {
if let Value::Sequence(s) = self {
Some(s)
@ -833,6 +847,13 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
}
}
pub fn into_set(self) -> Option<Set<N>> {
match self {
Value::Set(s) => Some(s),
_ => None,
}
}
pub fn as_set_mut(&mut self) -> Option<&mut Set<N>> {
if let Value::Set(s) = self {
Some(s)
@ -857,6 +878,13 @@ impl<N: NestedValue<D>, D: Embeddable> Value<N, D> {
}
}
pub fn into_dictionary(self) -> Option<Map<N, N>> {
match self {
Value::Dictionary(s) => Some(s),
_ => None,
}
}
pub fn as_dictionary_mut(&mut self) -> Option<&mut Map<N, N>> {
if let Value::Dictionary(s) = self {
Some(s)
@ -998,6 +1026,10 @@ impl<N: NestedValue<D>, D: Embeddable> Annotations<N, D> {
self.maybe_slice().unwrap_or(&[])
}
pub fn to_vec(self) -> Vec<N> {
self.0.unwrap_or_default()
}
pub fn modify<F>(&mut self, f: F) -> &mut Self
where
F: FnOnce(&mut Vec<N>)