sharedlib/symbol/
func_tracked.rs

1use FuncUnsafe;
2use Symbol;
3
4/// A pointer to a shared function which allows a user-provided ref-counting implementation to avoid outliving its library.
5#[derive(Debug)]
6pub struct FuncTracked<T, TLib> {
7    func: FuncUnsafe<T>,
8    _lib: TLib,
9}
10
11impl <T, TLib> FuncTracked<T, TLib> {
12    /// Creates a new [FuncTracked](struct.FuncTracked.html).
13    /// This should only be called within the library.
14    pub fn new(func: FuncUnsafe<T>, lib: TLib) -> Self {
15        FuncTracked {
16            func: func,
17            _lib: lib,
18        }
19    }
20}
21
22impl <T, TLib> Symbol<T> for FuncTracked<T, TLib>
23    where T: Copy {
24    unsafe fn get(&self) -> T {
25        self.func
26    }
27}
28
29impl <T, TLib> Clone for FuncTracked<T, TLib>
30    where T: Copy,
31          TLib: Clone {
32    fn clone(&self) -> Self {
33        FuncTracked {
34            func: self.func,
35            _lib: self._lib.clone(),
36        }
37    }
38}