pub unsafe trait VCopy<'a>: VClone<'a> {
// Provided method
fn vcopy(&'a self) -> VCopier<'a, Self> { ... }
}
Expand description
Support for shallow byte-wise copy of varlen types.
Types that implement this trait can be copied by a bulk copy of the byte buffer at which the object is stored.
§Examples
use varlen::prelude::*;
let s1: VBox<Str> = VBox::new(Str::copy("hello"));
let s2: VBox<Str> = VBox::new(s1.vcopy());
§Safety
Implementors of this trait must guarantee that this type is safe for
bytewise copy. Usually it is sufficient to guarantee that all fields
implement VCopy
.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<'a, A: VCopy<'a>, B: VCopy<'a>> VCopy<'a> for Tup2<A, B>
impl<'a, A: VCopy<'a>, B: VCopy<'a>, C: VCopy<'a>> VCopy<'a> for Tup3<A, B, C>
impl<'a, A: VCopy<'a>, B: VCopy<'a>, C: VCopy<'a>, D: VCopy<'a>> VCopy<'a> for Tup4<A, B, C, D>
impl<'a, A: VCopy<'a>, B: VCopy<'a>, C: VCopy<'a>, D: VCopy<'a>, E: VCopy<'a>> VCopy<'a> for Tup5<A, B, C, D, E>
impl<'a, Len: ArrayLen> VCopy<'a> for Str<Len>
Strings can be copied with fast memcpy.
§Examples
use varlen::prelude::*;
let arr = VBox::new(Str::copy("hello"));
let seq: Seq<Str> = seq![arr.vcopy(), arr.vcopy(), arr.vcopy()];
for a in seq.iter() {
assert_eq!(&a[..], "hello");
}
impl<'a, T: 'a + Copy> VCopy<'a> for FixedLen<T>
impl<'a, T: 'a + Copy, Len: ArrayLen> VCopy<'a> for Array<T, Len>
Arrays can be copied (fast memcpy) if their elements can.
§Examples
use varlen::prelude::*;
let arr = VBox::new(Array::copy(&[1u8, 2, 3]));
let seq: Seq<Array<u8>> = seq![arr.vcopy(), arr.vcopy(), arr.vcopy()]; // Copies the array
for a in seq.iter() {
assert_eq!(&a[..], &[1, 2, 3]);
}