Given that I have this enum:
enum SpecialSeries {
DA,
KT,
LD,
}
Now I want to build this string
"DA|KT|LD"
in order to use as pattern for RegEx. How should I code with strum
?
Thank you.
Given that I have this enum:
enum SpecialSeries {
DA,
KT,
LD,
}
Now I want to build this string
"DA|KT|LD"
in order to use as pattern for RegEx. How should I code with strum
?
Thank you.
If you're using strum
, then you can add #[derive(Debug, Display, EnumIter)]
to the enum. Then you can use SpecialSeries::iter()
to get an iterator over the enum, then use either a fold()
with the Display
implementation or, more simply, join()
from itertools
.
You can also use a custom macro for this:
enum_with_RegEx! {
#[derive(Debug)]
pub
enum MyEnum {
Foo,
Bar,
Baz,
}
}
fn main ()
{
assert_eq!(
MyEnum::REGEX,
"Foo|Bar|Baz",
);
}
Thanks, looking too advance to me. Will take time to learn more.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.