I'm trying to figure out how to deal with the fact that a Store owns it's data. With how my application works, I need to make a Store only borrow it's state while using it and then return the state. Also the thing that owns the Store must be 'static
, so I can't get away with a lifetime here.
Store::into_data
probably isn't the right solution since it would destroy any vm internal state.
I can't move the application state into the Store because I may destroy the current Store and move app state to a new store at runtime.
The Store documentation also seems to mention it should be a short lived object, but in my application the Store may be around for a very long time
https://doc.rust-lang.org/std/mem/fn.replace.html perhaps?
Lann Martin said:
I'm not sure mem::replace is going to solve my issue, let me type up something quickly
struct App {
state: State,
// most of the time a runtime will exist, but it can be replaced and exist for a short time with no runtime.
//
// However T needs to reference stuff in State. This would result in a self referential type.
//
//
runtime: Option<Store<T>>,
}
Ideally I'd prefer to avoid using ouroboros which would make a self referential type and instead or resorting to unsafe
Although I'm not sure ouroboros is even capable of describing a self referential type which may cease being self referential in the future
Actually scratch the code example I wrote, I need something more like:
struct App {
some_data: i32,
runtime: Option<Store<App>>, // where App is &mut self pretty much
}
Last updated: Dec 23 2024 at 13:07 UTC