Clippy is warning that the following ‘if let’ in push_char() is irrefutable, thus useless, and recommends replacing the ‘if let’ with ‘let’. What is the idiomatic rust way to address this warning?
#[derive(Clone, Debug, PartialEq)]
pub enum StrComponent {
Word(String),
Other(String),
}
impl StrComponent {
pub fn push_char(&mut self, c: char) {
if let StrComponent::Other(s) | StrComponent::Word(s) = self {
s.push(c);
}
}
}
Per Clippy’s feedback, I’ve tried replacing ‘if let’ with ‘let’ but that results in a compiler error. I’ve also Googled alternate ways of access the data within an enum variant, but ‘if let’ or match patterns dominate.
New contributor
user26320114 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.