Type Alias LStrHandle

Source
pub type LStrHandle<'a> = UHandle<'a, LStr>;
Expand description

Definition of a handle to an LabVIEW String. Helper for FFI definition and required for any functions that need to resize the string.

Aliased Type§

#[repr(transparent)]
pub struct LStrHandle<'a>(pub *mut *mut LStr, pub PhantomData<&'a LStr>);

Tuple Fields§

§0: *mut *mut LStr§1: PhantomData<&'a LStr>

Implementations§

Source§

impl LStrHandle<'_>

Implement features that require a full string handle rather than just the LStr type.

Requires the link feature.

Source

pub fn set(&mut self, value: &[u8]) -> Result<()>

Set the string as a binary value against the handle.

This function will resize the handle based on the size of the input value.

§Errors
  • This will error if the string handle is invalid (likely a null pointer).
§Example
use labview_interop::types::{LVStatusCode, LStrHandle};
#[no_mangle]
pub extern "C" fn hello_world(mut string: LStrHandle) -> LVStatusCode {
   let result = string.set(b"Hello World");
   result.into()
}
Source

pub fn set_str(&mut self, value: &str) -> Result<()>

Set string takes a Rust string and puts it into the LabVIEW String.

This is a two step process:

  1. Encode from Rust (UTF8) to LabVIEW encoding (based on system code page on Windows).
  2. Write this encoding into the LabVIEW string.

If the input is valid ASCII then no additional data copies are made. If not then this will allocate a new intermediate buffer to hold the decoded results before writing to the LabVIEW string.

Source

pub fn set_str_with_encoding( &mut self, encoder: &'static Encoding, value: &str, ) -> Result<()>

Set string with encoder takes a Rust string and puts it into the LabVIEW String.

This is a two step process:

  1. Encode from Rust (UTF8) to LabVIEW encoding with the provided encoder.
  2. Write this encoding into the LabVIEW string.

If the input is valid ASCII then no additional data copies are made. If not then this will allocate a new intermediate buffer to hold the decoded results before writing to the LabVIEW string.

The encoder should be an encoder provided by the encoding_rs crate.