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) -> IterIdentityCopied<Iter> ⓘ
pub fn iter_identity_copied(self) -> IterIdentityCopied<Iter> ⓘ
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> DynSend for EarlyBinder<I, T>
impl<I, T> DynSync for EarlyBinder<I, T>
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<T> Pointable for T
impl<T> Pointable for T
Source§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.