1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use encoder::EncodeContext;
12 use schema::{Lazy, LazySeq};
13 use rustc::ty::TyCtxt;
14 use rustc_serialize::Encodable;
16 /// The IsolatedEncoder provides facilities to write to crate metadata while
17 /// making sure that anything going through it is also feed into an ICH hasher.
18 pub struct IsolatedEncoder<'a, 'b: 'a, 'tcx: 'b> {
19 pub tcx: TyCtxt<'b, 'tcx, 'tcx>,
20 ecx: &'a mut EncodeContext<'b, 'tcx>,
23 impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
25 pub fn new(ecx: &'a mut EncodeContext<'b, 'tcx>) -> Self {
33 pub fn lazy<T>(&mut self, value: &T) -> Lazy<T>
39 pub fn lazy_seq<I, T>(&mut self, iter: I) -> LazySeq<T>
40 where I: IntoIterator<Item = T>,
43 self.ecx.lazy_seq(iter)
46 pub fn lazy_seq_ref<'x, I, T>(&mut self, iter: I) -> LazySeq<T>
47 where I: IntoIterator<Item = &'x T>,
50 self.ecx.lazy_seq_ref(iter)
53 pub fn lazy_seq_from_slice<T>(&mut self, slice: &[T]) -> LazySeq<T>
56 self.ecx.lazy_seq_ref(slice.iter())