1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use Result;
use DeserializeOwned;
use Serialize;
use Value;
/// Collector will collect a value which take `V` as template.
///
/// Implementor SHOULD deserialize into `V` directly and then serialize
/// into a [`serde_bridge::Value`] to make value merge possible.
///
/// Take `serde-env` as an example:
///
/// ```ignore
/// #[derive(Debug)]
/// pub struct Environment<V: DeserializeOwned + Serialize + Debug> {
/// phantom: PhantomData<V>,
/// }
///
/// impl<V> Collector<V> for Environment<V>
/// where
/// V: DeserializeOwned + Serialize + Debug,
/// {
/// fn collect(&mut self) -> Result<Value> {
/// let v: V = serde_env::from_env()?;
/// Ok(v.into_value()?)
/// }
/// }
/// ```
/// It's recommended to implement `IntoCollector` so that it can be used
/// in [`Builder::collect()`][`crate::Builder::collect()`] directly.