What's the normal way of dealing with "global" state in a Rust program using tokio? Or, to ask a more specific question expressing what I think I want: is there a way to teach the borrow checker that an object has a lifetime longer than the tokio event loop? /cc @ManishEarth
2
1
You could make a "proper" global using thread local state or lazy_static
1
You can otherwise specify the right outlives lifetime bounds but I'm not sure where they'd go, i'd need an example of what you'd want to do
1
I don't think I want a proper global since the "global" is set up differently in the running bot versus the tests. And it's state that's used in a bunch of functions. (That said, what I'm thinking of might fail on mutable vs. non-mutable borrows anyway... need to look.)
1
How are you starting the tokio event loop?
1
Replying to @khuey_ @ManishEarth
let mut core = Core::new().unwrap(); let mut irc_state = IRCState::new(ghtype, handle); let ircstream = ...; core.run(ircstream); ... but I could change it.

Mar 27, 2018 · 7:14 PM UTC

1
So what's the actual error message you get? Core::run doesn't require `static bounds on the future you hand it.
1
The actual error messages are from the borrow checker, about lifetimes of references in closures involved in an additional call to post to the Tokio event loop (handle.spawn(...)).
2