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>
impl<T: ?Sized> UPtr<T>
Sourcepub unsafe fn as_ref(&self) -> Result<&T>
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).
Sourcepub unsafe fn as_ref_mut(&self) -> Result<&mut T>
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<'_>>
impl UPtr<ErrorCluster<'_>>
Sourcepub fn wrap_function<R, E: ToLvError, F: FnOnce() -> Result<R, E>>(
&mut self,
return_on_error: R,
function: F,
) -> R
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)
})
}
Sourcepub fn wrap_return_status<E: ToLvError, F: FnOnce() -> Result<(), E>>(
&mut self,
function: F,
) -> LVStatusCode
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§
impl<T: Copy + ?Sized> Copy for UPtr<T>
impl<T: Eq + ?Sized> Eq for UPtr<T>
impl<T: ?Sized> Send for UPtr<T>
§Safety
- UPtr memory is managed by the Labview Memory Manager, which is thread safe