Enum bevy_internal::utils::CowArc
source · 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§
source§impl<'a, T> CowArc<'a, T>
impl<'a, T> CowArc<'a, T>
sourcepub 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.
sourcepub 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§
source§impl<T> From<&'static T> for CowArc<'static, T>where
T: ?Sized,
impl<T> From<&'static T> for CowArc<'static, T>where
T: ?Sized,
source§fn from(value: &'static T) -> CowArc<'static, T>
fn from(value: &'static T) -> CowArc<'static, T>
source§impl<'a, T> Ord for CowArc<'a, T>
impl<'a, T> Ord for CowArc<'a, T>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<'a, T> PartialEq for CowArc<'a, T>
impl<'a, T> PartialEq for CowArc<'a, T>
source§impl<'a, T> PartialOrd for CowArc<'a, T>where
T: PartialOrd + ?Sized,
impl<'a, T> PartialOrd for CowArc<'a, T>where
T: PartialOrd + ?Sized,
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: ?Sized> RefUnwindSafe for CowArc<'a, T>where
T: RefUnwindSafe,
impl<'a, T: ?Sized> Send for CowArc<'a, T>
impl<'a, T: ?Sized> Sync for CowArc<'a, T>
impl<'a, T: ?Sized> Unpin for CowArc<'a, T>
impl<'a, T: ?Sized> UnwindSafe for CowArc<'a, T>where
T: RefUnwindSafe,
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> 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
source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§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
.source§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
.source§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.source§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.source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.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<S, T> ParallelSlice<T> for S
impl<S, T> ParallelSlice<T> for S
source§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