/
send_producer.rs
83 lines (65 loc) · 1.84 KB
/
send_producer.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use crate::imp_prelude::*;
use crate::{Layout, NdProducer};
use std::ops::{Deref, DerefMut};
/// An NdProducer that is unconditionally `Send`.
#[repr(transparent)]
pub(crate) struct SendProducer<T> {
inner: T
}
impl<T> SendProducer<T> {
/// Create an unconditionally `Send` ndproducer from the producer
pub(crate) unsafe fn new(producer: T) -> Self { Self { inner: producer } }
}
unsafe impl<P> Send for SendProducer<P> { }
impl<P> Deref for SendProducer<P> {
type Target = P;
fn deref(&self) -> &P { &self.inner }
}
impl<P> DerefMut for SendProducer<P> {
fn deref_mut(&mut self) -> &mut P { &mut self.inner }
}
impl<P: NdProducer> NdProducer for SendProducer<P>
where P: NdProducer,
{
type Item = P::Item;
type Dim = P::Dim;
type Ptr = P::Ptr;
type Stride = P::Stride;
private_impl! {}
#[inline(always)]
fn raw_dim(&self) -> Self::Dim {
self.inner.raw_dim()
}
#[inline(always)]
fn equal_dim(&self, dim: &Self::Dim) -> bool {
self.inner.equal_dim(dim)
}
#[inline(always)]
fn as_ptr(&self) -> Self::Ptr {
self.inner.as_ptr()
}
#[inline(always)]
fn layout(&self) -> Layout {
self.inner.layout()
}
#[inline(always)]
unsafe fn as_ref(&self, ptr: Self::Ptr) -> Self::Item {
self.inner.as_ref(ptr)
}
#[inline(always)]
unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr {
self.inner.uget_ptr(i)
}
#[inline(always)]
fn stride_of(&self, axis: Axis) -> Self::Stride {
self.inner.stride_of(axis)
}
#[inline(always)]
fn contiguous_stride(&self) -> Self::Stride {
self.inner.contiguous_stride()
}
fn split_at(self, axis: Axis, index: usize) -> (Self, Self) {
let (a, b) = self.inner.split_at(axis, index);
(Self { inner: a }, Self { inner: b })
}
}