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:

§Example

use crossmist::{StaticRef, static_ref};

let num = static_ref!(i32, 123);
assert_eq!(*num, 123);

Implementations§

source§

impl<T> StaticRef<T>

source

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);
source

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> Clone for StaticRef<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for StaticRef<T>

source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Deref for StaticRef<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T: 'static> NonTrivialObject for StaticRef<T>

source§

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>

Deserialize a single object from a deserializer. Read more
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Object for T

source§

fn serialize_self(&self, s: &mut Serializer)

Serialize a single object into a serializer.
source§

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>

Deserialize a single object from a deserializer. Read more
source§

unsafe fn deserialize_on_heap<'a>( self: *const T, d: &mut Deserializer ) -> Result<Box<dyn Object + 'a>, Error>
where T: 'a,

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more