These are chat archives for rust-lang/rust

25th
Jun 2016
Daniel Collin
@emoon
Jun 25 2016 16:37
So what would the most “Rustified” way be to have shared “settings” (think GUI application) implemented? Passing around a settings struct is nice that it’s doesn’t run into issues dealing with lifetimes and such but passing it around the whole application kinda gets old fast. Using Rc<Settings> allows for immutable data only and I need to be able to (at one place in the code) to update the settings also. I could go for the whole RefCell<T> thing but I rather avoid it if possible.
Erik Hedvall
@Ogeon
Jun 25 2016 16:44
You could use something like lazy static to make it global. It will most likely require a RefCell, as well.
...just to present another alternative.
Daniel Collin
@emoon
Jun 25 2016 16:47
Yeah I thought about something like that as well
Erik Hedvall
@Ogeon
Jun 25 2016 16:49
It will have a slight performance impact on access, instead of for each time it's shared, so you may want to go for something reference like if it's frequently accessed. It may also be too low to be noticeable.
Daniel Collin
@emoon
Jun 25 2016 16:56
Yeah I think that should be fine really