diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2017-12-03 14:31:27 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2017-12-21 19:21:40 +0100 |
| commit | 84ce4f1c10f419916a4432cc3b021797f4dc4bfe (patch) | |
| tree | 663e8d83ecbef46fc271937d02786e9986e4b4c3 | |
| parent | 30733b3e68e0a6cc6466c881423ada562aa85b4e (diff) | |
| download | rust-84ce4f1c10f419916a4432cc3b021797f4dc4bfe.tar.gz rust-84ce4f1c10f419916a4432cc3b021797f4dc4bfe.zip | |
Add Encodable and Decodable impls for Arc<[T]>
| -rw-r--r-- | src/libserialize/collection_impls.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index d8ae9729224..de7eebe7bf3 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -15,6 +15,7 @@ use std::hash::{Hash, BuildHasher}; use {Decodable, Encodable, Decoder, Encoder}; use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSet}; use std::rc::Rc; +use std::sync::Arc; impl< T: Encodable @@ -218,3 +219,26 @@ impl<T: Decodable> Decodable for Rc<[T]> { }) } } + +impl<T: Encodable> Encodable for Arc<[T]> { + fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> { + s.emit_seq(self.len(), |s| { + for (index, e) in self.iter().enumerate() { + s.emit_seq_elt(index, |s| e.encode(s))?; + } + Ok(()) + }) + } +} + +impl<T: Decodable> Decodable for Arc<[T]> { + fn decode<D: Decoder>(d: &mut D) -> Result<Arc<[T]>, D::Error> { + d.read_seq(|d, len| { + let mut vec = Vec::with_capacity(len); + for index in 0..len { + vec.push(d.read_seq_elt(index, |d| Decodable::decode(d))?); + } + Ok(vec.into()) + }) + } +} \ No newline at end of file |
