pub struct SwitchTargets {
values: SmallVec<[u128; 1]>,
targets: SmallVec<[BasicBlockId; 2]>,
}Fields§
§values: SmallVec<[u128; 1]>Possible values. The locations to branch to in each case
are found in the corresponding indices from the targets vector.
targets: SmallVec<[BasicBlockId; 2]>Possible branch sites. The last element of this vector is used for the otherwise branch, so targets.len() == values.len() + 1 should hold.
Implementations§
Source§impl SwitchTargets
impl SwitchTargets
Sourcepub fn new(
targets: impl Iterator<Item = (u128, BasicBlockId)>,
otherwise: BasicBlockId,
) -> Self
pub fn new( targets: impl Iterator<Item = (u128, BasicBlockId)>, otherwise: BasicBlockId, ) -> Self
Creates switch targets from an iterator of values and target blocks.
The iterator may be empty, in which case the SwitchInt instruction is equivalent to
goto otherwise;.
Sourcepub fn static_if(value: u128, then: BasicBlockId, else_: BasicBlockId) -> Self
pub fn static_if(value: u128, then: BasicBlockId, else_: BasicBlockId) -> Self
Builds a switch targets definition that jumps to then if the tested value equals value,
and to else_ if not.
Sourcepub fn otherwise(&self) -> BasicBlockId
pub fn otherwise(&self) -> BasicBlockId
Returns the fallback target that is jumped to when none of the values match the operand.
Sourcepub fn iter(&self) -> impl Iterator<Item = (u128, BasicBlockId)> + '_
pub fn iter(&self) -> impl Iterator<Item = (u128, BasicBlockId)> + '_
Returns an iterator over the switch targets.
The iterator will yield tuples containing the value and corresponding target to jump to, not
including the otherwise fallback target.
Note that this may yield 0 elements. Only the otherwise branch is mandatory.
Sourcepub fn all_targets(&self) -> &[BasicBlockId] ⓘ
pub fn all_targets(&self) -> &[BasicBlockId] ⓘ
Returns a slice with all possible jump targets (including the fallback target).
Sourcepub fn target_for_value(&self, value: u128) -> BasicBlockId
pub fn target_for_value(&self, value: u128) -> BasicBlockId
Finds the BasicBlock to which this SwitchInt will branch given the
specific value. This cannot fail, as it’ll return the otherwise
branch if there’s not a specific match for the value.
Trait Implementations§
Source§impl Clone for SwitchTargets
impl Clone for SwitchTargets
Source§fn clone(&self) -> SwitchTargets
fn clone(&self) -> SwitchTargets
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SwitchTargets
impl Debug for SwitchTargets
Source§impl Hash for SwitchTargets
impl Hash for SwitchTargets
Source§impl PartialEq for SwitchTargets
impl PartialEq for SwitchTargets
Source§fn eq(&self, other: &SwitchTargets) -> bool
fn eq(&self, other: &SwitchTargets) -> bool
self and other values to be equal, and is used by ==.impl Eq for SwitchTargets
impl StructuralPartialEq for SwitchTargets
Auto Trait Implementations§
impl Freeze for SwitchTargets
impl RefUnwindSafe for SwitchTargets
impl Send for SwitchTargets
impl Sync for SwitchTargets
impl Unpin for SwitchTargets
impl UnsafeUnpin for SwitchTargets
impl UnwindSafe for SwitchTargets
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> HashEqLike<T> for T
impl<T> HashEqLike<T> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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