rgsl/
view.rs

1//
2// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
3//
4
5use crate::ffi::FFI;
6use std::marker::PhantomData;
7use std::ops::Deref;
8
9/// A struct which binds a type to a lifetime and prevent mutable access.
10pub struct View<'a, T> {
11    inner: T,
12    phantom: PhantomData<&'a ()>,
13}
14
15impl<'a, T> View<'a, T> {
16    pub(crate) fn new<P>(inner: *mut P) -> Self
17    where
18        T: FFI<P>,
19    {
20        Self {
21            inner: FFI::soft_wrap(inner),
22            phantom: PhantomData,
23        }
24    }
25}
26
27impl<'a, T> Deref for View<'a, T> {
28    type Target = T;
29
30    fn deref(&self) -> &Self::Target {
31        &self.inner
32    }
33}