Hello,
I defined multiple configuration profiles as multiple conts
with type NestedStructWithManyStructs
(funny name just for the example), and I use the profile in multiple functions, as you can see in the example.
At this moment, I have 20 functions that look similar to the example - the first line retrieves a reference to the profile and destructures a few fields that are needed in that function.
Could you please tell me if there are any performance implications, best practices, or other recommendations for this? Or maybe a different way to retrieve the config?
Thank you.
const PROFILE_FOO: NestedStructWithManyStructs = NestedStructWithManyStructs { data: "foo", data2: "foo" };
const PROFILE_BAR: NestedStructWithManyStructs = NestedStructWithManyStructs { data: "bar", data2: "bar" };
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NestedStructWithManyStructs<'a> {
pub data: &'a str,
pub data2: &'a str
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ConfigName {
Foo,
Bar
}
fn get_cf(name: &ConfigName) -> &NestedStructWithManyStructs {
match *name {
ConfigName::Foo => &PROFILE_FOO,
ConfigName::Bar => &PROFILE_BAR
}
}
fn do_something_1(foo: &str, cf: &ConfigName) {
let NestedStructWithManyStructs { data, .. } = get_cf(&cf);
// ...
}
fn do_something_2(foo: &str, cf: &ConfigName) {
let NestedStructWithManyStructs { data2, .. } = get_cf(&cf);
// ...
}
fn do_something_3(foo: &str, cf: &ConfigName) {
let NestedStructWithManyStructs { data, data2 } = get_cf(&cf);
// ...
}