pub struct SwitchFn;Expand description
Returns the result corresponding to the first matching candidate value.
SWITCH(expression, value1, result1, [value2, result2], ..., [default])
compares expression against each candidate from left to right.
§Remarks
- Matching is case-insensitive for text values.
- Numeric comparisons treat
IntandNumbervalues as compatible. - A trailing unmatched argument acts as the default result.
- When no candidate matches and no default is supplied, returns
#N/A. - Errors in
expressionpropagate immediately.
§Examples
=SWITCH("gold","silver",1,"gold",2,0)title: "Match a text label"
formula: '=SWITCH("gold","silver",1,"gold",2,0)'
expected: 2title: "Fall back to default"
formula: '=SWITCH(3,1,"one",2,"two","other")'
expected: "other"related:
- IF
- IFS
- CHOOSE
faq:
- q: "Does SWITCH compare text case-sensitively?"
a: "No. Text comparisons are case-insensitive in this implementation."
- q: "What happens when nothing matches?"
a: "SWITCH returns the trailing default when provided; otherwise it returns #N/A."[formualizer-docgen:schema:start] Name: SWITCH Type: SwitchFn Min args: 3 Max args: variadic Variadic: true Signature: SWITCH(arg1: any@scalar, arg2…: any@scalar) Arg schema: arg1{kinds=any,required=true,shape=scalar,by_ref=false,coercion=None,max=None,repeating=None,default=false}; arg2{kinds=any,required=true,shape=scalar,by_ref=false,coercion=None,max=None,repeating=None,default=false} Caps: PURE, SHORT_CIRCUIT [formualizer-docgen:schema:end]
Trait Implementations§
Source§impl Function for SwitchFn
[formualizer-docgen:schema:start]
Name: SWITCH
Type: SwitchFn
Min args: 3
Max args: variadic
Variadic: true
Signature: SWITCH(arg1…: any@scalar)
Arg schema: arg1{kinds=any,required=true,shape=scalar,by_ref=false,coercion=None,max=None,repeating=None,default=false}
Caps: PURE, SHORT_CIRCUIT
[formualizer-docgen:schema:end]
impl Function for SwitchFn
[formualizer-docgen:schema:start] Name: SWITCH Type: SwitchFn Min args: 3 Max args: variadic Variadic: true Signature: SWITCH(arg1…: any@scalar) Arg schema: arg1{kinds=any,required=true,shape=scalar,by_ref=false,coercion=None,max=None,repeating=None,default=false} Caps: PURE, SHORT_CIRCUIT [formualizer-docgen:schema:end]
fn name(&self) -> &'static str
fn min_args(&self) -> usize
fn variadic(&self) -> bool
fn arg_schema(&self) -> &'static [ArgSchema]
Source§fn eval<'a, 'b, 'c>(
&self,
args: &'c [ArgumentHandle<'a, 'b>],
_ctx: &dyn FunctionContext<'b>,
) -> Result<CalcValue<'b>, ExcelError>
fn eval<'a, 'b, 'c>( &self, args: &'c [ArgumentHandle<'a, 'b>], _ctx: &dyn FunctionContext<'b>, ) -> Result<CalcValue<'b>, ExcelError>
fn namespace(&self) -> &'static str
fn volatile(&self) -> bool
Source§fn aliases(&self) -> &'static [&'static str]
fn aliases(&self) -> &'static [&'static str]
Source§fn dependency_contract(
&self,
_arity: usize,
) -> Option<FunctionDependencyContract>
fn dependency_contract( &self, _arity: usize, ) -> Option<FunctionDependencyContract>
fn function_salt(&self) -> u64
Source§fn eval_reference<'a, 'b, 'c>(
&self,
_args: &'c [ArgumentHandle<'a, 'b>],
_ctx: &dyn FunctionContext<'b>,
) -> Option<Result<ReferenceType, ExcelError>>
fn eval_reference<'a, 'b, 'c>( &self, _args: &'c [ArgumentHandle<'a, 'b>], _ctx: &dyn FunctionContext<'b>, ) -> Option<Result<ReferenceType, ExcelError>>
Source§fn dispatch<'a, 'b, 'c>(
&self,
args: &'c [ArgumentHandle<'a, 'b>],
ctx: &dyn FunctionContext<'b>,
) -> Result<CalcValue<'b>, ExcelError>
fn dispatch<'a, 'b, 'c>( &self, args: &'c [ArgumentHandle<'a, 'b>], ctx: &dyn FunctionContext<'b>, ) -> Result<CalcValue<'b>, ExcelError>
Auto Trait Implementations§
impl Freeze for SwitchFn
impl RefUnwindSafe for SwitchFn
impl Send for SwitchFn
impl Sync for SwitchFn
impl Unpin for SwitchFn
impl UnsafeUnpin for SwitchFn
impl UnwindSafe for SwitchFn
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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