Skip to content

Commit

Permalink
Make Deserializers cloneable
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 23, 2016
1 parent be744f6 commit 07b1016
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ use std::marker::PhantomData;
use std::error;
use std::fmt;
use std::time::Duration;
use typemap::{Key, ShareMap};
use std::sync::Arc;
use typemap::{Key, ShareCloneMap};
use serde;
use serde_value::Value;

Expand Down Expand Up @@ -151,11 +152,12 @@ impl<T> ErasedDeserialize for DeserializeEraser<T>
struct KeyAdaptor<T: ?Sized>(PhantomData<T>);

impl<T: ?Sized + Any> Key for KeyAdaptor<T> {
type Value = HashMap<String, Box<ErasedDeserialize<Trait = T>>>;
type Value = HashMap<String, Arc<ErasedDeserialize<Trait = T>>>;
}

/// A container of `Deserialize`rs.
pub struct Deserializers(ShareMap);
#[derive(Clone)]
pub struct Deserializers(ShareCloneMap);

/// Creates a `Deserializers` with the following mappings:
///
Expand Down Expand Up @@ -282,7 +284,7 @@ impl Default for Deserializers {
impl Deserializers {
/// Creates a new `Deserializers` with no mappings.
pub fn new() -> Deserializers {
Deserializers(ShareMap::custom())
Deserializers(ShareCloneMap::custom())
}

/// Adds a mapping from the specified `kind` to a deserializer.
Expand All @@ -292,7 +294,7 @@ impl Deserializers {
self.0
.entry::<KeyAdaptor<T::Trait>>()
.or_insert_with(|| HashMap::new())
.insert(kind.to_owned(), Box::new(DeserializeEraser(deserializer)));
.insert(kind.to_owned(), Arc::new(DeserializeEraser(deserializer)));
}

/// Deserializes a value of a specific type and kind.
Expand Down

0 comments on commit 07b1016

Please sign in to comment.