pub struct DynamicString { /* private fields */ }Expand description
A Rust version of NvdDynamicString
A DynamicString is effectively a conversion of a heap allocated string designed to work with NvDialog
that works with the Rust side. In essence, it’s just another string type for Rust, but works with this crate instead.
This type is useful since version v0.10 of NvDialog when the API was completely rewritten to use NvdDynamicString, a separate
string type that addresses the limitations of working with raw character buffers and safety concerns.
Implementations§
Source§impl DynamicString
impl DynamicString
Sourcepub fn new<S: AsRef<str>>(data: Option<S>) -> Self
pub fn new<S: AsRef<str>>(data: Option<S>) -> Self
Create a new DynamicString from optional UTF-8 data.
- If
dataisSome, the contents are passed to the FFI (as a C string) and mirrored intoSelfas well. - If
dataisNone, a null is passed tonvd_string_new, which is expected (by the library) to produce an empty string.
Note that if you want to duplicate a string, you can use DynamicString::duplicate instead of
allocating a brand new one.
§Safety
The returned object can be modified safely, however note that any modifications are permanent and
if you received the DynamicString from another function, then trying to fetch it again will return your
modified string as the internal pointer was modified.
Sourcepub unsafe fn as_ptr(&self) -> *const c_char
pub unsafe fn as_ptr(&self) -> *const c_char
Returns a borrowed pointer to the internal string’s buffer.
§Safety
The returned pointer is only valid as long as self is. Additionally, if the internal data was corrupted,
this function may corrupt the program’s memory, therefore make sure self was not internally modified beforehand.
§Returns
A NULL-terminated, heap-allocated C-style string on success, or NULL if nvd_string_to_cstr failed.
Sourcepub fn duplicate(&self) -> Self
pub fn duplicate(&self) -> Self
Create a deep copy of this DynamicString.
Note that this function returns a truly unique DynamicString - It is safe to modify the returned value as
self does not point to it (and vice versa).
§Safety
This function is safe to use, unless the internal structure was corrupted beforehand, in which case nvd_duplicate_string
may return invalid or corrupt data. Make sure self has not been modified incorrectly before calling this function.
§Returns
A deep copy of self, assuming no errors from the FFI-side.