pub struct IfStatement { /* private fields */ }
Expand description
Represents an if statement.
Implementations§
Source§impl IfStatement
impl IfStatement
Sourcepub fn new(branches: Vec<IfBranch>, else_block: Option<Block>) -> Self
pub fn new(branches: Vec<IfBranch>, else_block: Option<Block>) -> Self
Creates a new if statement with the given branches and optional else block.
Sourcepub fn create(condition: impl Into<Expression>, block: impl Into<Block>) -> Self
pub fn create(condition: impl Into<Expression>, block: impl Into<Block>) -> Self
Creates a new if statement with a single condition and block.
Sourcepub fn with_tokens(self, tokens: IfStatementTokens) -> Self
pub fn with_tokens(self, tokens: IfStatementTokens) -> Self
Sets the tokens for this if statement.
Sourcepub fn set_tokens(&mut self, tokens: IfStatementTokens)
pub fn set_tokens(&mut self, tokens: IfStatementTokens)
Sets the tokens for this if statement.
Sourcepub fn get_tokens(&self) -> Option<&IfStatementTokens>
pub fn get_tokens(&self) -> Option<&IfStatementTokens>
Returns the tokens for this if statement, if any.
Sourcepub fn mutate_tokens(&mut self) -> Option<&mut IfStatementTokens>
pub fn mutate_tokens(&mut self) -> Option<&mut IfStatementTokens>
Returns a mutable reference to the tokens, if any.
Sourcepub fn with_branch(self, branch: IfBranch) -> Self
pub fn with_branch(self, branch: IfBranch) -> Self
Adds a branch to this if statement.
Sourcepub fn with_new_branch(
self,
condition: impl Into<Expression>,
block: impl Into<Block>,
) -> Self
pub fn with_new_branch( self, condition: impl Into<Expression>, block: impl Into<Block>, ) -> Self
Adds a new branch with the given condition and block.
Sourcepub fn with_else_block<B: Into<Block>>(self, block: B) -> Self
pub fn with_else_block<B: Into<Block>>(self, block: B) -> Self
Adds an else block to this if statement.
Sourcepub fn mutate_all_blocks(&mut self) -> Vec<&mut Block>
pub fn mutate_all_blocks(&mut self) -> Vec<&mut Block>
Returns mutable references to all blocks in this if statement.
Sourcepub fn get_branches(&self) -> &Vec<IfBranch>
pub fn get_branches(&self) -> &Vec<IfBranch>
Returns the branches of this if statement.
Sourcepub fn iter_branches(&self) -> impl Iterator<Item = &IfBranch>
pub fn iter_branches(&self) -> impl Iterator<Item = &IfBranch>
Returns an iterator over the branches.
Sourcepub fn branch_count(&self) -> usize
pub fn branch_count(&self) -> usize
Returns the number of branches.
Sourcepub fn mutate_branches(&mut self) -> &mut Vec<IfBranch>
pub fn mutate_branches(&mut self) -> &mut Vec<IfBranch>
Returns a mutable reference to the branches.
Sourcepub fn push_new_branch(
&mut self,
condition: impl Into<Expression>,
block: impl Into<Block>,
)
pub fn push_new_branch( &mut self, condition: impl Into<Expression>, block: impl Into<Block>, )
Adds a new branch with the given condition and block.
Sourcepub fn push_branch(&mut self, branch: IfBranch)
pub fn push_branch(&mut self, branch: IfBranch)
Adds a branch to this if statement.
Sourcepub fn get_else_block(&self) -> Option<&Block>
pub fn get_else_block(&self) -> Option<&Block>
Returns the else block, if any.
Sourcepub fn mutate_else_block(&mut self) -> &mut Option<Block>
pub fn mutate_else_block(&mut self) -> &mut Option<Block>
Returns a mutable reference to the else block option.
Sourcepub fn set_else_block(&mut self, block: impl Into<Block>)
pub fn set_else_block(&mut self, block: impl Into<Block>)
Sets the else block.
Sourcepub fn take_else_block(&mut self) -> Option<Block>
pub fn take_else_block(&mut self) -> Option<Block>
Removes the else block, if any.
Sourcepub fn retain_branches_mut(
&mut self,
filter: impl FnMut(&mut IfBranch) -> bool,
) -> bool
pub fn retain_branches_mut( &mut self, filter: impl FnMut(&mut IfBranch) -> bool, ) -> bool
Filters branches in-place, ensuring at least one branch remains.
Sourcepub fn mutate_first_token(&mut self) -> &mut Token
pub fn mutate_first_token(&mut self) -> &mut Token
Returns a mutable reference to the first token for this statement, creating it if missing.
Sourcepub fn mutate_last_token(&mut self) -> &mut Token
pub fn mutate_last_token(&mut self) -> &mut Token
Returns a mutable reference to the last token for this statement, creating it if missing.
Sourcepub fn clear_comments(&mut self)
pub fn clear_comments(&mut self)
Clears all comments from the tokens in this node.
Sourcepub fn clear_whitespaces(&mut self)
pub fn clear_whitespaces(&mut self)
Clears all whitespaces information from the tokens in this node.
Trait Implementations§
Source§impl Clone for IfStatement
impl Clone for IfStatement
Source§fn clone(&self) -> IfStatement
fn clone(&self) -> IfStatement
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for IfStatement
impl Debug for IfStatement
Source§impl From<IfStatement> for Statement
impl From<IfStatement> for Statement
Source§fn from(if_statement: IfStatement) -> Statement
fn from(if_statement: IfStatement) -> Statement
Source§impl PartialEq for IfStatement
impl PartialEq for IfStatement
impl Eq for IfStatement
impl StructuralPartialEq for IfStatement
Auto Trait Implementations§
impl Freeze for IfStatement
impl RefUnwindSafe for IfStatement
impl Send for IfStatement
impl Sync for IfStatement
impl Unpin for IfStatement
impl UnwindSafe for IfStatement
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
Source§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
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