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
use FuncUnsafe; use std::marker::PhantomData; use Symbol; /// A pointer to a shared function which uses a bound lifetime to avoid outliving its library. pub struct Func<'a, T> { func: FuncUnsafe<T>, lifetime: PhantomData<&'a ()>, } impl <'a, T> Func<'a, T> { /// Creates a new [Func](struct.Func.html). /// This should only be called within the library. pub fn new(func: FuncUnsafe<T>) -> Self { Func { func: func, lifetime: PhantomData, } } } impl <'a, T> Symbol<T> for Func<'a, T> where T: Copy { unsafe fn get(&self) -> T { self.func } }