http_type/lifetime/trait.rs
1/// Trait for types that can be converted to a `'static` reference.
2///
3/// This trait provides a way to obtain a `'static` reference or mutable reference from
4/// a reference to `Self`, enabling safe lifetime extension for
5/// certain use cases where the object is known to live for the entire
6/// program duration.
7pub trait Lifetime {
8 /// Converts a reference to `Self` into a `'static` reference.
9 ///
10 /// # Returns
11 ///
12 /// - `&'static Self`: A reference to the instance with a `'static` lifetime.
13 ///
14 /// # Safety
15 ///
16 /// - The address is guaranteed to be a valid `Self` instance
17 /// that was previously converted from a reference and is managed by the runtime.
18 unsafe fn leak(&self) -> &'static Self;
19
20 /// Converts a reference to `Self` into a `'static` mutable reference.
21 ///
22 /// # Returns
23 ///
24 /// - `&'static mut Self`: A mutable reference to the instance with a `'static` lifetime.
25 ///
26 /// # Safety
27 ///
28 /// - The address is guaranteed to be a valid `Self` instance
29 /// that was previously converted from a reference and is managed by the runtime.
30 unsafe fn leak_mut(&self) -> &'static mut Self;
31}