I was trying to create a mutable struct (an interrupt descriptor table) with s static lifetime. Since the static mut is not safe, I use an alternative of lazy_static and mutex like this
use lazy_static::lazy_static;
use spin::Mutex;
lazy_static! {
pub static ref IDT: Mutex<idt_type> = Mutex::new(...);
}
My 'idt_type' has a method which takes a static self as perameter like this:
impl idt_type {
pub fn load(&'static self);
}
However is I try to use this method like this
IDT.lock().load();
the complier will complain since lock() returns a non static MutexGuard:
IDT.lock().load();
| ^^^^^^^^^^-------- temporary value is freed at the end of this statement
| |
| creates a temporary which is freed while still in use
| argument requires that borrow lasts for `'static`
Is there any way to work around?
&'static selfrather than&'a self? The mutex won't ever given you a'staticreference as that would imply you have locked the data forever, and thus don't need a mutex.load()is to load the address of idt into the reg, and the idt should have a static lifetime. Anyway, I'm trying to find an alternative forstatic mut