varlen

Trait VCopy

Source
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§

Source

fn vcopy(&'a self) -> VCopier<'a, Self>

Returns an initializer that does a bulk byte copy of self.

§Examples
use varlen::prelude::*;

let s1: VBox<Str> = VBox::new(Str::copy("hello"));
let s2: VBox<Str> = VBox::new(s1.vcopy());

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§

Source§

impl<'a, A: VCopy<'a>, B: VCopy<'a>> VCopy<'a> for Tup2<A, B>

Source§

impl<'a, A: VCopy<'a>, B: VCopy<'a>, C: VCopy<'a>> VCopy<'a> for Tup3<A, B, C>

Source§

impl<'a, A: VCopy<'a>, B: VCopy<'a>, C: VCopy<'a>, D: VCopy<'a>> VCopy<'a> for Tup4<A, B, C, D>

Source§

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>

Source§

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");
}
Source§

impl<'a, T: 'a + Copy> VCopy<'a> for FixedLen<T>

Source§

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]);
}