]> git.proxmox.com Git - rustc.git/blame - src/librustc_metadata/isolated_encoder.rs
New upstream version 1.36.0+dfsg1
[rustc.git] / src / librustc_metadata / isolated_encoder.rs
CommitLineData
9fa01778
XL
1use crate::encoder::EncodeContext;
2use crate::schema::{Lazy, LazySeq};
7cac9316 3use rustc::ty::TyCtxt;
7cac9316
XL
4use 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.
8pub struct IsolatedEncoder<'a, 'b: 'a, 'tcx: 'b> {
9 pub tcx: TyCtxt<'b, 'tcx, 'tcx>,
10 ecx: &'a mut EncodeContext<'b, 'tcx>,
7cac9316
XL
11}
12
13impl<'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;
7cac9316 17 IsolatedEncoder {
3b2f2976
XL
18 tcx,
19 ecx,
7cac9316
XL
20 }
21 }
22
23 pub fn lazy<T>(&mut self, value: &T) -> Lazy<T>
ff7c6d11 24 where T: Encodable
7cac9316 25 {
7cac9316
XL
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>,
ff7c6d11 31 T: Encodable
7cac9316 32 {
ff7c6d11 33 self.ecx.lazy_seq(iter)
7cac9316
XL
34 }
35
36 pub fn lazy_seq_ref<'x, I, T>(&mut self, iter: I) -> LazySeq<T>
37 where I: IntoIterator<Item = &'x T>,
ff7c6d11 38 T: 'x + Encodable
7cac9316 39 {
ff7c6d11 40 self.ecx.lazy_seq_ref(iter)
7cac9316
XL
41 }
42
43 pub fn lazy_seq_from_slice<T>(&mut self, slice: &[T]) -> LazySeq<T>
ff7c6d11 44 where T: Encodable
7cac9316 45 {
7cac9316
XL
46 self.ecx.lazy_seq_ref(slice.iter())
47 }
7cac9316 48}