Trait scratchpad::SliceSource [] [src]

pub trait SliceSource<T: ?Sized> where
    T: SliceLike
{ fn as_slice_like(&self) -> &T; fn as_slice_like_ptr(&self) -> *const T { ... } }

Trait for sources of slice data provided to Marker trait methods.

SliceSource is implemented for static arrays and slice references. If either the std or unstable features are enabled, boxed slice and Vec instances can be used as slice sources as well.

SliceSource on its own is only usable for Clone and Copy data sources. For move operations, the SliceMoveSource subtrait provides additional functionality for moving slices out of supported types.

Required Methods

Returns a SliceLike reference to this object's data.

Examples

use scratchpad::SliceSource;

// `value` is an `[f64; 1]`...
let value = [3.14159];

// ...but `value_slice` is a `&[f64]`...
let value_slice = value.as_slice_like();
assert_eq!(value_slice.len(), 1);
assert_eq!(value_slice[0], 3.14159);

// ...that references the same memory as `value`.
assert!(std::ptr::eq(&value[0], &value_slice[0]));

Provided Methods

Returns a SliceLike pointer to this object's data.

Examples

use scratchpad::SliceSource;

// `value` is an `[f64; 1]`...
let value = [3.14159];

unsafe {
    // ...but `value_slice_ptr` is a `*const [f64]`...
    let value_slice_ptr = value.as_slice_like_ptr();
    assert_eq!((*value_slice_ptr).len(), 1);
    assert_eq!((*value_slice_ptr)[0], 3.14159);

    // ...that references the same memory as `value`.
    assert!(std::ptr::eq(&value[0], &(*value_slice_ptr)[0]));
}

Implementations on Foreign Types

impl<'a, T: ?Sized> SliceSource<T> for &'a T where
    T: SliceLike
[src]

impl<T: ?Sized> SliceSource<T> for Box<T> where
    T: SliceLike
[src]

impl<T> SliceSource<[T]> for Vec<T>
[src]

impl<'a, T: ?Sized> SliceSource<T> for &'a Box<T> where
    T: SliceLike
[src]

impl<'a, T> SliceSource<[T]> for &'a Vec<T>
[src]

Implementors