Skip to main content

OptionExpand

Struct OptionExpand 

Source
pub struct OptionExpand<T: CubeType> { /* private fields */ }

Implementations§

Source§

impl<T: CubeType> OptionExpand<T>

Source

pub fn __expand_is_none_method( &self, scope: &Scope, ) -> <bool as CubeType>::ExpandType

Returns true if the option is a None value.

§Examples
let x: Option<u32> = Some(2);
assert_eq!(x.is_none(), false);

let x: Option<u32> = None;
assert_eq!(x.is_none(), true);
Source

pub fn __expand_unwrap_method( self, scope: &Scope, ) -> <T as CubeType>::ExpandType

Returns the contained Some value, consuming the self value.

Because this function may panic, its use is generally discouraged. Panics are meant for unrecoverable errors, and may abort the entire program.

Instead, prefer to use pattern matching and handle the None case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default. In functions returning Option, you can use the ? (try) operator.

§Panics

Panics if the self value equals None.

§Examples
let x = Some("air");
assert_eq!(x.unwrap(), "air");
let x: Option<&str> = None;
assert_eq!(x.unwrap(), "air"); // fails
Source

pub fn __expand_unwrap_or_method( self, scope: &Scope, default: <T as CubeType>::ExpandType, ) -> <T as CubeType>::ExpandType

Returns the contained Some value or a provided default.

Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.

§Examples
assert_eq!(Some("car").unwrap_or("bike"), "car");
assert_eq!(None.unwrap_or("bike"), "bike");
Source

pub fn __expand_unwrap_or_default_method( self, scope: &Scope, ) -> <T as CubeType>::ExpandType

Returns the contained Some value or a default.

Consumes the self argument then, if Some, returns the contained value, otherwise if None, returns the default value for that type.

§Examples
let x: Option<u32> = None;
let y: Option<u32> = Some(12);

assert_eq!(x.unwrap_or_default(), 0);
assert_eq!(y.unwrap_or_default(), 12);
Source

pub fn __expand_and_method<U>( self, scope: &Scope, optb: <Option<U> as CubeType>::ExpandType, ) -> <Option<U> as CubeType>::ExpandType

Returns None if the option is None, otherwise returns optb.

Arguments passed to and are eagerly evaluated; if you are passing the result of a function call, it is recommended to use and_then, which is lazily evaluated.

§Examples
let x = Some(2);
let y: Option<&str> = None;
assert_eq!(x.and(y), None);

let x: Option<u32> = None;
let y = Some("foo");
assert_eq!(x.and(y), None);

let x = Some(2);
let y = Some("foo");
assert_eq!(x.and(y), Some("foo"));

let x: Option<u32> = None;
let y: Option<&str> = None;
assert_eq!(x.and(y), None);
Source

pub fn __expand_or_method( self, scope: &Scope, optb: <Option<T> as CubeType>::ExpandType, ) -> <Option<T> as CubeType>::ExpandType

Returns the option if it contains a value, otherwise returns optb.

Arguments passed to or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use or_else, which is lazily evaluated.

§Examples
let x = Some(2);
let y = None;
assert_eq!(x.or(y), Some(2));

let x = None;
let y = Some(100);
assert_eq!(x.or(y), Some(100));

let x = Some(2);
let y = Some(100);
assert_eq!(x.or(y), Some(2));

let x: Option<u32> = None;
let y = None;
assert_eq!(x.or(y), None);
Source

pub fn __expand_xor_method( self, scope: &Scope, optb: <Option<T> as CubeType>::ExpandType, ) -> <Option<T> as CubeType>::ExpandType

Returns Some if exactly one of self, optb is Some, otherwise returns None.

§Examples
let x = Some(2);
let y: Option<u32> = None;
assert_eq!(x.xor(y), Some(2));

let x: Option<u32> = None;
let y = Some(2);
assert_eq!(x.xor(y), Some(2));

let x = Some(2);
let y = Some(2);
assert_eq!(x.xor(y), None);

let x: Option<u32> = None;
let y: Option<u32> = None;
assert_eq!(x.xor(y), None);
Source

pub fn __expand_zip_method<U>( self, scope: &Scope, other: <Option<U> as CubeType>::ExpandType, ) -> <Option<(T, U)> as CubeType>::ExpandType

Zips self with another Option.

If self is Some(s) and other is Some(o), this method returns Some((s, o)). Otherwise, None is returned.

§Examples
let x = Some(1);
let y = Some("hi");
let z = None::<u8>;

assert_eq!(x.zip(y), Some((1, "hi")));
assert_eq!(x.zip(z), None);
Source§

impl<T: CubeType<ExpandType: RuntimeAssign> + IntoRuntime + Default, U: CubeType<ExpandType: RuntimeAssign> + IntoRuntime + Default> OptionExpand<(T, U)>

Source

pub fn __expand_unzip_method( self, scope: &Scope, ) -> (<Option<T> as CubeType>::ExpandType, <Option<U> as CubeType>::ExpandType)

Unzips an option containing a tuple of two options.

If self is Some((a, b)) this method returns (Some(a), Some(b)). Otherwise, (None, None) is returned.

§Examples
let x = Some((1, "hi"));
let y = None::<(u8, u32)>;

assert_eq!(x.unzip(), (Some(1), Some("hi")));
assert_eq!(y.unzip(), (None, None));

Trait Implementations§

Source§

impl<T: CubeType> AsMutExpand for OptionExpand<T>

Source§

fn __expand_ref_mut_method(&mut self, _: &Scope) -> &mut Self

Source§

fn __expand_as_mut_method(&mut self, scope: &Scope) -> &mut T

Source§

impl<T: CubeType> AsRefExpand for OptionExpand<T>

Source§

fn __expand_ref_method(&self, _: &Scope) -> &Self

Source§

fn __expand_as_ref_method(&self, scope: &Scope) -> &T

Source§

impl<T: CubeType> Assign for OptionExpand<T>
where <T as CubeType>::ExpandType: Assign,

Source§

fn __expand_assign_method(&mut self, scope: &Scope, value: Self)

Assign value to self in scope.
Source§

impl<T: CubeType> CubeDebug for OptionExpand<T>

Source§

fn set_debug_name(&self, scope: &Scope, name: &'static str)

Set the debug name of this type’s expansion. Should do nothing for types that don’t appear at runtime
Source§

impl<T: CubeType> CubeEnum for OptionExpand<T>

Source§

type RuntimeValue = <T as CubeType>::ExpandType

Source§

fn discriminant(&self) -> NativeExpand<i32>

Source§

fn runtime_value(self) -> Self::RuntimeValue

Return the runtime value of this enum, if only one variant has a value. Should return () for all other cases.
Source§

fn discriminant_of(variant_name: &'static str) -> i32

Source§

fn discriminant_of_value(&self, variant_name: &'static str) -> i32

Source§

impl<T: CubeType> ExpandTypeClone for OptionExpand<T>

Source§

fn clone_unchecked(&self) -> Self

Unchecked clone that only clones the conceptual runtime value. Should only be used in cases where each copy is used in a mutually exclusive branch (i.e. match, runtime enums). This is intentionally separated from Rust’s Clone semantics and should only be used for the conceptual expand values, never real data. Using two values in the same branch is undefined behaviour.
Source§

impl<T: CubeType> IntoExpand for OptionExpand<T>

Source§

type Expand = OptionExpand<T>

Source§

fn into_expand(self, _: &Scope) -> Self

Source§

impl<T: CubeType> IntoMut for OptionExpand<T>

Source§

fn into_mut(self, scope: &Scope) -> Self

Convert the variable into a potentially new mutable variable in scope, copying if needed.
Source§

impl<T: CubeType> RuntimeAssign for OptionExpand<T>

Source§

fn init_mut(&self, scope: &Scope) -> Self

Create a new mutable variable of this type in scope.

Auto Trait Implementations§

§

impl<T> Freeze for OptionExpand<T>
where <T as CubeType>::ExpandType: Freeze,

§

impl<T> RefUnwindSafe for OptionExpand<T>

§

impl<T> Send for OptionExpand<T>
where <T as CubeType>::ExpandType: Send,

§

impl<T> Sync for OptionExpand<T>
where <T as CubeType>::ExpandType: Sync,

§

impl<T> Unpin for OptionExpand<T>
where <T as CubeType>::ExpandType: Unpin,

§

impl<T> UnsafeUnpin for OptionExpand<T>

§

impl<T> UnwindSafe for OptionExpand<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.