tensorgraph_sys/
lib.rs

1#![allow(incomplete_features)]
2#![feature(
3    generic_associated_types,
4    allocator_api,
5    alloc_layout_extra,
6    nonnull_slice_from_raw_parts,
7    slice_ptr_len,
8    ptr_metadata,
9    maybe_uninit_slice,
10    generic_const_exprs,
11    thread_local,
12    once_cell,
13    layout_for_ptr
14)]
15#![warn(clippy::pedantic, clippy::nursery)]
16#![allow(
17    clippy::module_name_repetitions,
18    clippy::float_cmp,
19    clippy::many_single_char_names,
20    clippy::similar_names
21)]
22
23/// Provides implementation of a Device [`Box`]
24pub mod boxed;
25
26pub mod device;
27
28/// Provides standard pointer types
29pub mod ptr;
30
31mod vec;
32mod zero;
33
34pub use vec::{DefaultVec, Vec};
35pub use zero::Zero;
36
37/// Represents a type that can be 'viewed' (derefed).
38/// Mimics the impl for [`std::ops::Deref`] but makes use of `GAT`'s in order
39/// to provide non `&` refs. Useful for things like tensor views.
40pub trait View {
41    type Ref<'a>
42    where
43        Self: 'a;
44
45    fn view(&self) -> Self::Ref<'_>;
46}
47
48/// Represents a type that can be mutably 'viewed' (derefed).
49/// Mimics the impl for [`std::ops::DerefMut`] but makes use of `GAT`'s in order
50/// to provide non `&mut` refs. Useful for things like tensor views.
51pub trait ViewMut {
52    type Mut<'a>
53    where
54        Self: 'a;
55
56    fn view_mut(&mut self) -> Self::Mut<'_>;
57}
58
59impl<D: std::ops::Deref> View for D {
60    type Ref<'a>
61    where
62        Self: 'a,
63    = &'a D::Target;
64
65    fn view(&self) -> Self::Ref<'_> {
66        self
67    }
68}
69
70impl<D: std::ops::DerefMut> ViewMut for D {
71    type Mut<'a>
72    where
73        Self: 'a,
74    = &'a mut D::Target;
75
76    fn view_mut(&mut self) -> Self::Mut<'_> {
77        self
78    }
79}