cubecl_core/frontend/
const_expand.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use super::{CubeContext, CubeType};

pub trait OptionExt<T: CubeType> {
    fn __expand_unwrap_or_else_method(
        self,
        _context: &mut CubeContext,
        other: impl FnOnce(&mut CubeContext) -> T::ExpandType,
    ) -> T::ExpandType;

    fn __expand_unwrap_or_method(
        self,
        _context: &mut CubeContext,
        other: T::ExpandType,
    ) -> T::ExpandType;
}

impl<T: CubeType + Into<T::ExpandType>> OptionExt<T> for Option<T> {
    fn __expand_unwrap_or_else_method(
        self,
        context: &mut CubeContext,
        other: impl FnOnce(&mut CubeContext) -> <T as CubeType>::ExpandType,
    ) -> <T as CubeType>::ExpandType {
        self.map(Into::into).unwrap_or_else(|| other(context))
    }

    fn __expand_unwrap_or_method(
        self,
        _context: &mut CubeContext,
        other: <T as CubeType>::ExpandType,
    ) -> <T as CubeType>::ExpandType {
        self.map(Into::into).unwrap_or(other)
    }
}