Struct crossmist::static_ref::StaticRef
source · pub struct StaticRef<T: 'static> { /* private fields */ }
Expand description
A &'static T
implementing Object
.
See the documentation for crossmist::static_ref
for a tutorial-grade explanation.
This type can be created via one of the following two ways:
- Safely, via
static_ref!
- Unsafely, via
StaticRef::new_unchecked
§Example
use crossmist::{StaticRef, static_ref};
let num = static_ref!(i32, 123);
assert_eq!(*num, 123);
Implementations§
source§impl<T> StaticRef<T>
impl<T> StaticRef<T>
sourcepub unsafe fn new_unchecked(reference: &'static T) -> Self
pub unsafe fn new_unchecked(reference: &'static T) -> Self
Create StaticRef
from a 'static
reference.
This is an unsafe function – consider using the safe wrapper static_ref!
instead.
§Safety
This function is safe to call if:
- The referenced value must have existed since the beginning of the program execution (e.g.
the return value of
Box::leak
won’t work), and - The referenced value is located outside of a dynamic library.
§Example
use crossmist::StaticRef;
static NUM: i32 = 123;
let num = unsafe { StaticRef::new_unchecked(&NUM) };
assert_eq!(*num, 123);
sourcepub fn get(self) -> &'static T
pub fn get(self) -> &'static T
Extract the underlying reference.
StaticRef<T>
implements Deref
, so this function is only provided for completeness
and should seldom be used: instead of static_ref.get().<...>
just do static_ref.<...>
.
Trait Implementations§
source§impl<T: 'static> NonTrivialObject for StaticRef<T>
impl<T: 'static> NonTrivialObject for StaticRef<T>
source§fn serialize_self_non_trivial(&self, s: &mut Serializer)
fn serialize_self_non_trivial(&self, s: &mut Serializer)
Serialize a single object into a serializer.
source§unsafe fn deserialize_self_non_trivial(d: &mut Deserializer) -> Result<Self>
unsafe fn deserialize_self_non_trivial(d: &mut Deserializer) -> Result<Self>
Deserialize a single object from a deserializer. Read more
impl<T> Copy for StaticRef<T>
Auto Trait Implementations§
impl<T> Freeze for StaticRef<T>
impl<T> RefUnwindSafe for StaticRef<T>where
T: RefUnwindSafe,
impl<T> !Send for StaticRef<T>
impl<T> !Sync for StaticRef<T>
impl<T> Unpin for StaticRef<T>
impl<T> UnwindSafe for StaticRef<T>where
T: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Object for Twhere
T: NonTrivialObject,
impl<T> Object for Twhere
T: NonTrivialObject,
source§fn serialize_self(&self, s: &mut Serializer)
fn serialize_self(&self, s: &mut Serializer)
Serialize a single object into a serializer.
source§fn serialize_slice(elements: &[T], s: &mut Serializer)
fn serialize_slice(elements: &[T], s: &mut Serializer)
Serialize an array of objects into a serializer.
source§unsafe fn deserialize_self(d: &mut Deserializer) -> Result<T, Error>
unsafe fn deserialize_self(d: &mut Deserializer) -> Result<T, Error>
Deserialize a single object from a deserializer. Read more