Struct UPtr

Source
pub struct UPtr<T: ?Sized>(/* private fields */);
Expand description

A pointer from LabVIEW for the data.

In general, these should be avoided in favor of UHandle which allows for more functionality such as resizing types.

Implementations§

Source§

impl<T: ?Sized> UPtr<T>

Source

pub fn new(ptr: *mut T) -> Self

Create a new UPtr from a raw pointer

Source

pub unsafe fn as_ref(&self) -> Result<&T>

Get a reference to the internal type. Errors if the pointer is null.

§Safety

This is a wrapper around pointer::as_ref and so must follow its safety rules. Namely:

  • When calling this method, you have to ensure that either the pointer is null or all of the following is true:
  • The pointer must be properly aligned.
  • It must be “dereferenceable” in the sense defined in [the module documentation].
  • The pointer must point to an initialized instance of T.
  • You must enforce Rust’s aliasing rules, since the returned lifetime ’a is arbitrarily chosen and does not necessarily reflect the actual lifetime of the data. In particular, while this reference exists, the memory the pointer points to must not get mutated (except inside UnsafeCell).
Source

pub unsafe fn as_ref_mut(&self) -> Result<&mut T>

Get a mutable reference to the internal type. Errors if pointer contains a null.

§Safety

This method wraps the pointer::as_mut method and so follows its safety rules which require all of the following is true:

  • The pointer must be properly aligned.
  • It must be “dereferenceable” in the sense defined in the module documentation.
  • The pointer must point to an initialized instance of T.
  • You must enforce Rust’s aliasing rules, since the returned lifetime ’a is arbitrarily chosen and does not necessarily reflect the actual lifetime of the data. In particular, while this reference exists, the memory the pointer points to must not get accessed (read or written) through any other pointer.
Source§

impl UPtr<ErrorCluster<'_>>

Source

pub fn wrap_function<R, E: ToLvError, F: FnOnce() -> Result<R, E>>( &mut self, return_on_error: R, function: F, ) -> R

Wrap the provided function in error handling to match LabVIEW semantics.

i.e. no execution on error in, convert return errors into error cluster.

§Parameters
  • return_on_error - The value to return if an error.
  • function - The function to wrap. This is intended to be a closure for easy use.
§Example
use labview_interop::types::ErrorClusterPtr;
use labview_interop::errors::LVInteropError;
use labview_interop::types::LStrHandle;

#[no_mangle]
pub extern "C" fn example_function(mut error_cluster: ErrorClusterPtr, mut string_input: LStrHandle) -> i32 {
  error_cluster.wrap_function(42, || -> Result<i32, LVInteropError> {
   // Do some work
   string_input.set_str("Hello World")?;
  Ok(42)
 })
}
Source

pub fn wrap_return_status<E: ToLvError, F: FnOnce() -> Result<(), E>>( &mut self, function: F, ) -> LVStatusCode

Wrap the provided function in error handling to match LabVIEW semantics.

i.e. no execution on error in, convert return errors into error cluster.

This version returns the LabVIEW status code of the error. To return a different value, see ErrorClusterPtr::wrap_function.

§Parameters
  • function - The function to wrap. This is intended to be a closure for easy use.
§Example
use labview_interop::types::{ErrorClusterPtr, LVStatusCode};
use labview_interop::errors::LVInteropError;
use labview_interop::types::LStrHandle;

#[no_mangle]
pub extern "C" fn example_function(mut error_cluster: ErrorClusterPtr, mut string_input: LStrHandle) -> LVStatusCode {
  error_cluster.wrap_return_status(|| -> Result<(), LVInteropError> {
   // Do some work
   string_input.set_str("Hello World")?;
    Ok(())

 })
}

Trait Implementations§

Source§

impl<T: Clone + ?Sized> Clone for UPtr<T>

Source§

fn clone(&self) -> UPtr<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + ?Sized> Debug for UPtr<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ?Sized> Deref for UPtr<T>

Source§

fn deref(&self) -> &Self::Target

Extract the target type.

This will panic if the handle or internal pointer is null.

Source§

type Target = T

The resulting type after dereferencing.
Source§

impl<T: ?Sized> DerefMut for UPtr<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Deref to a mutable reference.

This will panic if the handle or internal pointer is null.

Source§

impl<T: PartialEq + ?Sized> PartialEq for UPtr<T>

Source§

fn eq(&self, other: &UPtr<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy + ?Sized> Copy for UPtr<T>

Source§

impl<T: Eq + ?Sized> Eq for UPtr<T>

Source§

impl<T: ?Sized> Send for UPtr<T>

§Safety

  • UPtr memory is managed by the Labview Memory Manager, which is thread safe
Source§

impl<T: ?Sized> StructuralPartialEq for UPtr<T>

Source§

impl<T: ?Sized> Sync for UPtr<T>

Auto Trait Implementations§

§

impl<T> Freeze for UPtr<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for UPtr<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Unpin for UPtr<T>
where T: ?Sized,

§

impl<T> UnwindSafe for UPtr<T>
where T: RefUnwindSafe + ?Sized,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> LVCopy for T
where T: Copy,