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