]> git.lizzy.rs Git - rust.git/blob - src/librustc_metadata/isolated_encoder.rs
Auto merge of #58246 - pmccarter:master, r=oli-obk
[rust.git] / src / librustc_metadata / isolated_encoder.rs
1 use crate::encoder::EncodeContext;
2 use crate::schema::{Lazy, LazySeq};
3 use rustc::ty::TyCtxt;
4 use rustc_serialize::Encodable;
5
6 /// The IsolatedEncoder provides facilities to write to crate metadata while
7 /// making sure that anything going through it is also feed into an ICH hasher.
8 pub struct IsolatedEncoder<'a, 'b: 'a, 'tcx: 'b> {
9     pub tcx: TyCtxt<'b, 'tcx, 'tcx>,
10     ecx: &'a mut EncodeContext<'b, 'tcx>,
11 }
12
13 impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
14
15     pub fn new(ecx: &'a mut EncodeContext<'b, 'tcx>) -> Self {
16         let tcx = ecx.tcx;
17         IsolatedEncoder {
18             tcx,
19             ecx,
20         }
21     }
22
23     pub fn lazy<T>(&mut self, value: &T) -> Lazy<T>
24         where T: Encodable
25     {
26         self.ecx.lazy(value)
27     }
28
29     pub fn lazy_seq<I, T>(&mut self, iter: I) -> LazySeq<T>
30         where I: IntoIterator<Item = T>,
31               T: Encodable
32     {
33         self.ecx.lazy_seq(iter)
34     }
35
36     pub fn lazy_seq_ref<'x, I, T>(&mut self, iter: I) -> LazySeq<T>
37         where I: IntoIterator<Item = &'x T>,
38               T: 'x + Encodable
39     {
40         self.ecx.lazy_seq_ref(iter)
41     }
42
43     pub fn lazy_seq_from_slice<T>(&mut self, slice: &[T]) -> LazySeq<T>
44         where T: Encodable
45     {
46         self.ecx.lazy_seq_ref(slice.iter())
47     }
48 }