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
//
// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
//

use crate::ffi::FFI;
use std::marker::PhantomData;
use std::ops::Deref;

/// A struct which binds a type to a lifetime and prevent mutable access.
pub struct View<'a, T> {
    inner: T,
    phantom: PhantomData<&'a ()>,
}

impl<'a, T> View<'a, T> {
    pub(crate) fn new<P>(inner: *mut P) -> Self
    where
        T: FFI<P>,
    {
        Self {
            inner: FFI::soft_wrap(inner),
            phantom: PhantomData,
        }
    }
}

impl<'a, T> Deref for View<'a, T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}