Trait ArenaCached

Source
pub trait ArenaCached<'tcx>: Sized {
    type Provided;
    type Allocated: 'tcx;

    // Required method
    fn alloc_in_arena(
        arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated,
        value: Self::Provided,
    ) -> Self;
}
Expand description

Helper trait that allows arena_cache queries to return Option<&T> instead of &Option<T>, and avoid allocating None in the arena.

An arena-cached query must be declared to return a type that implements this trait, i.e. either &'tcx T or Option<&'tcx T>. This trait then determines the types returned by the provider and stored in the arena, and provides a function to bridge between the three types.

Required Associated Types§

Source

type Provided

Type that is returned by the query provider.

Source

type Allocated: 'tcx

Type that is stored in the arena.

Required Methods§

Source

fn alloc_in_arena( arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated, value: Self::Provided, ) -> Self

Takes a provided value, and allocates it in the arena (if appropriate) with the help of the given arena_alloc closure.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'tcx, T> ArenaCached<'tcx> for Option<&'tcx T>

Source§

type Allocated = T

The provide value is Option<T>, but we only store T in the arena.

Source§

type Provided = Option<T>

Source§

fn alloc_in_arena( arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated, value: Self::Provided, ) -> Self

Source§

impl<'tcx, T> ArenaCached<'tcx> for &'tcx T

Source§

type Provided = T

Source§

type Allocated = T

Source§

fn alloc_in_arena( arena_alloc: impl Fn(Self::Allocated) -> &'tcx Self::Allocated, value: Self::Provided, ) -> Self

Implementors§