Skip to main content

## ArenaCached

# Trait ArenaCached

Source

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

        // Required method
        fn alloc_in_arena(
            tcx: TyCtxt<'tcx>,
            typed_arena: &'tcx TypedArena<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( tcx: TyCtxt<'tcx>, typed_arena: &'tcx TypedArena<Self::Allocated>, value: Self::Provided, ) -> Self

Takes a provided value, and allocates it in an appropriate arena, unless the particular value doesn’t need allocation (e.g. `None`).

## 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( tcx: TyCtxt<'tcx>, typed_arena: &'tcx TypedArena<T>, value: Option<T>, ) -> Self

Source§

### impl<'tcx, T> ArenaCached<'tcx> for Result<&'tcx T, ErrorGuaranteed>

Source§

#### type Allocated = T

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

Source§

#### type Provided = Result<T, ErrorGuaranteed>

Source§

#### fn alloc_in_arena( tcx: TyCtxt<'tcx>, typed_arena: &'tcx TypedArena<T>, value: Result<T, ErrorGuaranteed>, ) -> Self

Source§

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

Source§

#### type Provided = T

Source§

#### type Allocated = T

Source§

#### fn alloc_in_arena( tcx: TyCtxt<'tcx>, typed_arena: &'tcx TypedArena<T>, value: T, ) -> Self

## Implementors§