Hi all,
I'm not sure the best way to describe what I'm trying to figure out, as the words that come to mind have specific meanings in Rust. If there is a term for this, please do let me know!
So, I have an app that can send metrics to a backend which is super useful. However, I only want to do that if it is defined in the config file. I'm using config
to handle that side of things and it works really well. The metrics part of the config is held in an Option
. I've tried a few ways of using the config, but something like is where I've ended up:
if let Some(metrics_config) = get_metrics_config() {
..
}
I create a number of things inside the if
block that I need back at the top level in the main
function (such as the Tokio async handle). I've tried a few things, such as making a tuple with the values I care about and using that as the last expression but that seems a bit awkward:
let result = if let Some(metrics_config) = get_metrics_config() {
..
..
(thing_a, thing_b, thing_c)
}
What would be a more idiomatic way to do this? Or should I be taking a totally different approach?
Thanks so much!