Help find macros or crate

i need construction:
SomeStruct::new()
#[if variable is Some(arg1)]
.func1(arg1)
#[else]
.func2(arg2)

if #[if] return true: add .func1() to SomeStruct::new() -> SomeStruct::new().func1(arg1)
if #[if] return false: add .func2() to SomeStruct::new() -> SomeStruct::new().func2(arg2)

I'm not sure I understand, but a match expression might help:

let some_struct = SomeStruct::new();
match arg1 {
    Some(_) => some_struct.func1(arg1),
    None => some_struct.func2(arg2),
}

Are you looking to do this conditional at runtime (i.e. change the flow of execution based on something's value) or compile time (change execution based on things when you compiled the code)?

For the former, you are probably looking for the Control Flow chapter from The Rust Programming Language (sometimes just called The Book).

The latter is more advanced and typically used to make things cross-platform (i.e. you may change a method based on whether it's Linux/Windows or x86-64/arm). The Forms of conditional compilation chapter from The Rust Reference does a pretty good job of explaining how it can be used.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.