pub struct EarlyBinder<I: Interner, T> {
value: T,
_tcx: PhantomData<I>,
}
Expand description
Similar to super::Binder
except that it tracks early bound generics, i.e. struct Foo<T>(T)
needs T
instantiated immediately. This type primarily exists to avoid forgetting to call
instantiate
.
If you don’t have anything to instantiate
, you may be looking for
instantiate_identity
or skip_binder
.
Fields§
§value: T
§_tcx: PhantomData<I>
Implementations§
source§impl<I: Interner, T> EarlyBinder<I, T>
impl<I: Interner, T> EarlyBinder<I, T>
pub fn bind(value: T) -> EarlyBinder<I, T>
pub fn as_ref(&self) -> EarlyBinder<I, &T>
pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>where
F: FnOnce(T) -> U,
pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
pub fn rebind<U>(&self, value: U) -> EarlyBinder<I, U>
sourcepub fn skip_binder(self) -> T
pub fn skip_binder(self) -> T
Skips the binder and returns the “bound” value.
This can be used to extract data that does not depend on generic parameters
(e.g., getting the DefId
of the inner value or getting the number of
arguments of an FnSig
). Otherwise, consider using
instantiate_identity
.
To skip the binder on x: &EarlyBinder<I, T>
to obtain &T
, leverage
EarlyBinder::as_ref
: x.as_ref().skip_binder()
.
See also Binder::skip_binder
, which is
the analogous operation on super::Binder
.
source§impl<I: Interner, T> EarlyBinder<I, Option<T>>
impl<I: Interner, T> EarlyBinder<I, Option<T>>
pub fn transpose(self) -> Option<EarlyBinder<I, T>>
source§impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>where
Iter::Item: TypeFoldable<I>,
impl<I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>where
Iter::Item: TypeFoldable<I>,
pub fn iter_instantiated<A>(
self,
cx: I,
args: A,
) -> IterInstantiated<I, Iter, A> ⓘwhere
A: SliceLike<Item = I::GenericArg>,
sourcepub fn iter_identity(self) -> Iter::IntoIter
pub fn iter_identity(self) -> Iter::IntoIter
Similar to instantiate_identity
,
but on an iterator of TypeFoldable
values.
source§impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
impl<'s, I: Interner, Iter: IntoIterator> EarlyBinder<I, Iter>
pub fn iter_instantiated_copied( self, cx: I, args: &'s [I::GenericArg], ) -> IterInstantiatedCopied<'s, I, Iter> ⓘ
sourcepub fn iter_identity_copied(
self,
) -> impl Iterator<Item = <<Iter as IntoIterator>::Item as Deref>::Target>
pub fn iter_identity_copied( self, ) -> impl Iterator<Item = <<Iter as IntoIterator>::Item as Deref>::Target>
Similar to instantiate_identity
,
but on an iterator of values that deref to a TypeFoldable
.
source§impl<I: Interner, T: IntoIterator> EarlyBinder<I, T>
impl<I: Interner, T: IntoIterator> EarlyBinder<I, T>
pub fn transpose_iter(self) -> EarlyBinderIter<I, T::IntoIter> ⓘ
source§impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T>
impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T>
pub fn instantiate<A>(self, cx: I, args: A) -> Twhere
A: SliceLike<Item = I::GenericArg>,
sourcepub fn instantiate_identity(self) -> T
pub fn instantiate_identity(self) -> T
Makes the identity replacement T0 => T0, ..., TN => TN
.
Conceptually, this converts universally bound variables into placeholders
when inside of a given item.
For example, consider for<T> fn foo<T>(){ .. }
:
- Outside of
foo
,T
is bound (represented by the presence ofEarlyBinder
). - Inside of the body of
foo
, we treatT
as a placeholder by callinginstantiate_identity
to discharge theEarlyBinder
.
sourcepub fn no_bound_vars(self) -> Option<T>
pub fn no_bound_vars(self) -> Option<T>
Returns the inner value, but only if it contains no bound vars.
Trait Implementations§
source§impl<I, T> Clone for EarlyBinder<I, T>
impl<I, T> Clone for EarlyBinder<I, T>
source§impl<I, T> Debug for EarlyBinder<I, T>
impl<I, T> Debug for EarlyBinder<I, T>
source§impl<I, T> Hash for EarlyBinder<I, T>
impl<I, T> Hash for EarlyBinder<I, T>
source§impl<I: Interner, T, __CTX> HashStable<__CTX> for EarlyBinder<I, T>
impl<I: Interner, T, __CTX> HashStable<__CTX> for EarlyBinder<I, T>
fn hash_stable(&self, __hcx: &mut __CTX, __hasher: &mut StableHasher)
source§impl<I, T> Ord for EarlyBinder<I, T>
impl<I, T> Ord for EarlyBinder<I, T>
source§impl<I, T> PartialEq for EarlyBinder<I, T>
impl<I, T> PartialEq for EarlyBinder<I, T>
source§impl<I, T> PartialOrd for EarlyBinder<I, T>
impl<I, T> PartialOrd for EarlyBinder<I, T>
impl<I, T> Copy for EarlyBinder<I, T>
impl<I, T> Eq for EarlyBinder<I, T>
impl<I: Interner, T> !TypeFoldable<I> for EarlyBinder<I, T>
For early binders, you should first call instantiate
before using any visitors.
impl<I: Interner, T> !TypeVisitable<I> for EarlyBinder<I, T>
For early binders, you should first call instantiate
before using any visitors.
Auto Trait Implementations§
impl<I, T> Freeze for EarlyBinder<I, T>where
T: Freeze,
impl<I, T> RefUnwindSafe for EarlyBinder<I, T>where
T: RefUnwindSafe,
I: RefUnwindSafe,
impl<I, T> Send for EarlyBinder<I, T>
impl<I, T> Sync for EarlyBinder<I, T>
impl<I, T> Unpin for EarlyBinder<I, T>
impl<I, T> UnwindSafe for EarlyBinder<I, T>where
T: UnwindSafe,
I: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.