cubecl_core/frontend/
const_expand.rs

1use super::{CubeContext, CubeType};
2
3pub trait OptionExt<T: CubeType> {
4    fn __expand_unwrap_or_else_method(
5        self,
6        _context: &mut CubeContext,
7        other: impl FnOnce(&mut CubeContext) -> T::ExpandType,
8    ) -> T::ExpandType;
9
10    fn __expand_unwrap_or_method(
11        self,
12        _context: &mut CubeContext,
13        other: T::ExpandType,
14    ) -> T::ExpandType;
15}
16
17impl<T: CubeType + Into<T::ExpandType>> OptionExt<T> for Option<T> {
18    fn __expand_unwrap_or_else_method(
19        self,
20        context: &mut CubeContext,
21        other: impl FnOnce(&mut CubeContext) -> <T as CubeType>::ExpandType,
22    ) -> <T as CubeType>::ExpandType {
23        self.map(Into::into).unwrap_or_else(|| other(context))
24    }
25
26    fn __expand_unwrap_or_method(
27        self,
28        _context: &mut CubeContext,
29        other: <T as CubeType>::ExpandType,
30    ) -> <T as CubeType>::ExpandType {
31        self.map(Into::into).unwrap_or(other)
32    }
33}