I am trying to implement my own log::Loger which caches them in a. vec and then pushes them to a remote server.
However, log.set_logger(x) requires x to be a reference with a static lifetime, and I cannot for the life of me figure out how to create a non-trivial struct and tell rust it is static.
My struct:
pub struct LogStoreClient {
pub logs: Arc<RwLock<Vec<Message>>>,
}
impl log::Log for LogStoreClient {...}
Things I've tried:
-
static LOGGER = LogStoreClient { logs:...}fails becausecalls in statics are limited to constant functions, tuple structs and tuple variants -
static LOGGER = LogStoreClient::default()fails for the same reason -
lazy_static!crate works but rust no longer understands that LogStoreClient implementslog::Log - banging my head against a different type of wall, but that still hurts
It's driving me insane, and I can't believe I am the first person to ever want my own instance of a log::Log with state.
(The reason for the Arc<RwLock is because log::Log takes in &self not &mut self)
Help ![]()