[[matchesマクロ]]を使う。 ## 例 ```rust #[derive(Debug)] enum Record { Data(String), Comment(String), } fn main() { let records = vec![ Record::Data("one".to_string()), Record::Data("two".to_string()), Record::Data("three".to_string()), Record::Comment("end".to_string()), ]; let results = records .iter() .filter(|x| matches!(x, Record::Data(_))) .collect::<Vec<_>>(); println!("{:?}", results); // [Data("one"), Data("two"), Data("three")] } ``` ## 参考 - https://stackoverflow.com/questions/25576748/how-to-compare-enum-without-pattern-matching