Struct PtrWrapper

Source
pub struct PtrWrapper<T> { /* private fields */ }

Implementations§

Source§

impl<T> PtrWrapper<T>

Source

pub unsafe fn new( ptr: *mut T, destroy_fn: unsafe extern "C" fn(ptr: *mut T) -> Status, ) -> PtrWrapper<T>

Examples found in repository?
examples/log_gaze.rs (line 34)
23fn run_demo() -> Result<(), TobiiError> {
24    unsafe{
25        let custom_log = CustomLog {
26            log_context: ptr::null_mut(),
27            log_func: Some(custom_log_fn)
28        };
29
30        println!("Initializing API!");
31        let mut api_ptr: *mut Api = mem::zeroed();
32        let status = tobii_api_create( &mut api_ptr as *mut *mut Api, ptr::null_mut(), &custom_log as *const _);
33        status_to_result(status)?;
34        let api = PtrWrapper::new(api_ptr, tobii_api_destroy);
35
36        let devices = helpers::list_devices(api.ptr())?;
37        println!("{:?}", devices);
38
39        if devices.len() < 1 {
40            println!("No devices");
41            return Ok(());
42        }
43
44        let url_c_string = CString::new(devices[0].clone()).unwrap();
45        let url_c = url_c_string.as_c_str();
46        let mut device_ptr: *mut Device = mem::zeroed();
47        let status = tobii_device_create(api.ptr(), url_c.as_ptr(), &mut device_ptr as *mut *mut Device);
48        status_to_result(status)?;
49        let device = PtrWrapper::new(device_ptr, tobii_device_destroy);
50
51        let status = tobii_gaze_point_subscribe(device.ptr(), Some(gaze_callback), ptr::null_mut());
52        let _subscription = PtrWrapper::new(device.ptr(), tobii_gaze_point_unsubscribe);
53        status_to_result(status)?;
54        for _i in 1..1000 {
55            let status = helpers::wait_for_device_callbacks(device.ptr());
56            match status_to_result(status) {
57                Err(TobiiError::TimedOut) => continue,
58                Err(TobiiError::ConnectionFailed) => {
59                    status_to_result(helpers::reconnect(device.ptr()))?;
60                    continue;
61                },
62                Err(e) => return Err(e),
63                Ok(()) => (),
64            }
65
66            let status = tobii_device_process_callbacks(device.ptr());
67            if status == TOBII_ERROR_CONNECTION_FAILED {
68                status_to_result(helpers::reconnect(device.ptr()))?;
69                continue;
70            }
71            status_to_result(status)?;
72        }
73    }
74    Ok(())
75}
Source

pub fn ptr(&self) -> *mut T

Examples found in repository?
examples/log_gaze.rs (line 36)
23fn run_demo() -> Result<(), TobiiError> {
24    unsafe{
25        let custom_log = CustomLog {
26            log_context: ptr::null_mut(),
27            log_func: Some(custom_log_fn)
28        };
29
30        println!("Initializing API!");
31        let mut api_ptr: *mut Api = mem::zeroed();
32        let status = tobii_api_create( &mut api_ptr as *mut *mut Api, ptr::null_mut(), &custom_log as *const _);
33        status_to_result(status)?;
34        let api = PtrWrapper::new(api_ptr, tobii_api_destroy);
35
36        let devices = helpers::list_devices(api.ptr())?;
37        println!("{:?}", devices);
38
39        if devices.len() < 1 {
40            println!("No devices");
41            return Ok(());
42        }
43
44        let url_c_string = CString::new(devices[0].clone()).unwrap();
45        let url_c = url_c_string.as_c_str();
46        let mut device_ptr: *mut Device = mem::zeroed();
47        let status = tobii_device_create(api.ptr(), url_c.as_ptr(), &mut device_ptr as *mut *mut Device);
48        status_to_result(status)?;
49        let device = PtrWrapper::new(device_ptr, tobii_device_destroy);
50
51        let status = tobii_gaze_point_subscribe(device.ptr(), Some(gaze_callback), ptr::null_mut());
52        let _subscription = PtrWrapper::new(device.ptr(), tobii_gaze_point_unsubscribe);
53        status_to_result(status)?;
54        for _i in 1..1000 {
55            let status = helpers::wait_for_device_callbacks(device.ptr());
56            match status_to_result(status) {
57                Err(TobiiError::TimedOut) => continue,
58                Err(TobiiError::ConnectionFailed) => {
59                    status_to_result(helpers::reconnect(device.ptr()))?;
60                    continue;
61                },
62                Err(e) => return Err(e),
63                Ok(()) => (),
64            }
65
66            let status = tobii_device_process_callbacks(device.ptr());
67            if status == TOBII_ERROR_CONNECTION_FAILED {
68                status_to_result(helpers::reconnect(device.ptr()))?;
69                continue;
70            }
71            status_to_result(status)?;
72        }
73    }
74    Ok(())
75}

Trait Implementations§

Source§

impl<T> Drop for PtrWrapper<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PtrWrapper<T>

§

impl<T> RefUnwindSafe for PtrWrapper<T>
where T: RefUnwindSafe,

§

impl<T> !Send for PtrWrapper<T>

§

impl<T> !Sync for PtrWrapper<T>

§

impl<T> Unpin for PtrWrapper<T>

§

impl<T> UnwindSafe for PtrWrapper<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.