pub enum CowArc<'a, T>where
T: 'static + ?Sized,{
Borrowed(&'a T),
Static(&'static T),
Owned(Arc<T>),
}
Expand description
Much like a Cow
, but owned values are Arc-ed to make clones cheap. This should be used for values that
are cloned for use across threads and change rarely (if ever).
This also makes an opinionated tradeoff by adding a CowArc::Static
and implementing [From<&'static T>
] instead of
[From<'a T>
]. This preserves the static context and prevents conversion to CowArc::Owned
in cases where a reference
is known to be static. This is an optimization that prevents allocations and atomic ref-counting.
This means that static references should prefer From::from
or CowArc::Static
and non-static references must
use CowArc::Borrowed
.
Variants§
Borrowed(&'a T)
A borrowed value
Static(&'static T)
A static value reference. This exists to avoid conversion to CowArc::Owned
in cases where a reference is
known to be static. This is an optimization that prevents allocations and atomic ref-counting.
Owned(Arc<T>)
An owned Arc
-ed value
Implementations§
§impl<'a, T> CowArc<'a, T>
impl<'a, T> CowArc<'a, T>
pub fn into_owned(self) -> CowArc<'static, T>
pub fn into_owned(self) -> CowArc<'static, T>
Converts this into an “owned” value. If internally a value is borrowed, it will be cloned into an “owned Arc
”.
If it is already a CowArc::Owned
or a CowArc::Static
, it will remain unchanged.
pub fn clone_owned(&self) -> CowArc<'static, T>
pub fn clone_owned(&self) -> CowArc<'static, T>
Clones into an owned [CowArc<'static>
]. If internally a value is borrowed, it will be cloned into an “owned Arc
”.
If it is already a CowArc::Owned
or CowArc::Static
, the value will be cloned.
This is equivalent to .clone().into_owned()
.
Trait Implementations§
§impl<T> From<&'static T> for CowArc<'static, T>where
T: ?Sized,
impl<T> From<&'static T> for CowArc<'static, T>where
T: ?Sized,
§fn from(value: &'static T) -> CowArc<'static, T>
fn from(value: &'static T) -> CowArc<'static, T>
§impl<'a, T> Ord for CowArc<'a, T>
impl<'a, T> Ord for CowArc<'a, T>
§impl<'a, T> PartialEq for CowArc<'a, T>
impl<'a, T> PartialEq for CowArc<'a, T>
§impl<'a, T> PartialOrd for CowArc<'a, T>where
T: PartialOrd + ?Sized,
impl<'a, T> PartialOrd for CowArc<'a, T>where
T: PartialOrd + ?Sized,
§fn partial_cmp(&self, other: &CowArc<'a, T>) -> Option<Ordering>
fn partial_cmp(&self, other: &CowArc<'a, T>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<'a, T> Eq for CowArc<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for CowArc<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for CowArc<'a, T>where
T: RefUnwindSafe + ?Sized,
impl<'a, T> Send for CowArc<'a, T>
impl<'a, T> Sync for CowArc<'a, T>
impl<'a, T> Unpin for CowArc<'a, T>where
T: ?Sized,
impl<'a, T> UnwindSafe for CowArc<'a, T>where
T: RefUnwindSafe + ?Sized,
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<S, T> ParallelSlice<T> for S
impl<S, T> ParallelSlice<T> for S
§fn par_chunk_map<F, R>(
&self,
task_pool: &TaskPool,
chunk_size: usize,
f: F
) -> Vec<R>
fn par_chunk_map<F, R>( &self, task_pool: &TaskPool, chunk_size: usize, f: F ) -> Vec<R>
chunks_size
or less and maps the chunks
in parallel across the provided task_pool
. One task is spawned in the task pool
for every chunk. Read more§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.source§impl<T> ToHex for T
impl<T> ToHex for T
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)