Trait concrete_core::math::tensor::AsRefSlice[][src]

pub trait AsRefSlice {
    type Element;
    fn as_slice(&self) -> &[Self::Element]
Notable traits for &'_ [u8]
impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
; }
Expand description

A trait allowing to extract a slice from a tensor.

This trait is one of the two traits which allows to use Tensor whith any data container. This trait basically allows to extract a slice &[T] out of a container, to implement operations directly on the slice:

// Implementing AsSlice for Vec<T>
impl<Element> AsSlice for Vec<Element> {
    type Element = Element;
    fn as_slice(&self) -> &[Element] {
        self.as_slice()
    }
}

It is akin to the std::borrow::Borrow trait from the standard library, but it is local to this crate (which makes this little explanation possible), and the scalar type is an associated type. Having an associated type instead of a generic type, tends to make signatures a little leaner.

Finally, you should note that we have a blanket implementation that implements AsView for Tensor<Cont> where Cont is itself AsView:

impl<Cont> AsView for Tensor<Cont>
where
    Cont: AsView,
{
    type Scalar = Cont::Scalar;
    fn as_view(&self) -> &[Self::Scalar] {
        // implementation
    }
}

This is blanket implementation is used by the methods of the Tensor structure for instance.

Associated Types

The type of the elements of the collection.

Required methods

Returns a slice from the container.

Implementations on Foreign Types

Implementors