pub unsafe trait DataType: Debug + Clone {
type Inner;
Show 18 methods
// Required methods
fn data_type() -> *const UA_DataType;
unsafe fn from_raw(src: Self::Inner) -> Self;
fn into_raw(self) -> Self::Inner;
// Provided methods
fn type_name() -> &'static str { ... }
fn init() -> Self { ... }
fn raw_ref(src: &Self::Inner) -> &Self { ... }
fn raw_mut(src: &mut Self::Inner) -> &mut Self { ... }
fn clone_raw(src: &Self::Inner) -> Self { ... }
fn clone_into_raw(&self, dst: &mut Self::Inner) { ... }
fn move_into_raw(self, dst: &mut Self::Inner) { ... }
fn leak_into_raw(self) -> *mut Self::Inner { ... }
unsafe fn to_raw_copy(this: &Self) -> Self::Inner { ... }
unsafe fn as_ref(&self) -> &Self::Inner { ... }
unsafe fn as_mut(&mut self) -> &mut Self::Inner { ... }
unsafe fn as_ptr(&self) -> *const Self::Inner { ... }
unsafe fn as_mut_ptr(&mut self) -> *mut Self::Inner { ... }
fn print(this: &Self) -> Option<String> { ... }
fn order(this: &Self, other: &Self) -> UA_Order { ... }
}Expand description
Transparent wrapper for OPC UA data type.
§Safety
It must be possible to transmute between the type that implements DataType and the inner
type Inner. This implies that #[repr(transparent)] must be used on types that implement
this trait and the inner type must be Inner.
In addition, the inner type must not contain self-references (in Rust terms, it would have to
implement the Unpin trait). This is usually the case for types from open62541_sys, as
they are regularly passed by value to functions in order to transfer ownership.
Required Associated Types§
Required Methods§
Sourcefn data_type() -> *const UA_DataType
fn data_type() -> *const UA_DataType
Gets open62541 data type record.
The result can be passed to functions in open62541 that deal with arbitrary data types.
Sourceunsafe fn from_raw(src: Self::Inner) -> Self
unsafe fn from_raw(src: Self::Inner) -> Self
Creates wrapper by taking ownership of value.
When Self is dropped, UA_clear() is used to free allocations held by the inner type.
Move only values into Self that can be cleared in-place such as stack-allocated values
(but no heap-allocated values created by UA_new()).
§Safety
Ownership of the value passes to Self. This must only be used for values that are not
contained within other values that may be dropped (such as attributes in other data types).
In this case use clone_raw() instead to clone data instead of taking ownership.
Sourcefn into_raw(self) -> Self::Inner
fn into_raw(self) -> Self::Inner
Gives up ownership and returns value.
The returned value must be re-wrapped with from_raw() or cleared manually with
UA_clear() to free internal allocations and not leak memory.
Provided Methods§
Sourcefn init() -> Self
fn init() -> Self
Creates wrapper initialized with defaults.
This uses UA_init() to initialize the value and make all attributes well-defined.
Depending on the type, additional attributes may need to be initialized for the value to be
actually useful afterwards.
Sourcefn clone_raw(src: &Self::Inner) -> Self
fn clone_raw(src: &Self::Inner) -> Self
Creates wrapper by cloning value from src.
This uses UA_copy() to deeply copy an existing value without transferring ownership.
The original value must be cleared with UA_clear(), or deleted with UA_delete() if
allocated on the heap, to avoid memory leaks. If src is borrowed from another data type
wrapper, that wrapper will make sure of this.
Sourcefn clone_into_raw(&self, dst: &mut Self::Inner)
fn clone_into_raw(&self, dst: &mut Self::Inner)
Clones value into dst.
This uses UA_copy() to deeply copy an existing value without transferring ownership.
Existing data in dst is cleared with UA_clear() before cloning the value; it is safe
to use this operation on already initialized target values.
Sourcefn move_into_raw(self, dst: &mut Self::Inner)
fn move_into_raw(self, dst: &mut Self::Inner)
Moves value into dst, giving up ownership.
Existing data in dst is cleared with UA_clear() before moving the value; it is safe
to use this operation on already initialized target values.
After this, it is the responsibility of dst to eventually clean up the data.
Sourcefn leak_into_raw(self) -> *mut Self::Inner
fn leak_into_raw(self) -> *mut Self::Inner
Leaks wrapped value onto the heap.
This turns a stack-allocated value into a heap-allocated one, without issuing a deep copy. In other words, only the local memory allocation is copied (moved from stack to heap) and any memory that is already heap-allocated (e.g. string contents) stays where it is.
The returned value must be passed into another owned data structure or freed manually with
UA_delete() to free internal allocations and not leak memory.
Sourceunsafe fn to_raw_copy(this: &Self) -> Self::Inner
unsafe fn to_raw_copy(this: &Self) -> Self::Inner
Creates copy without giving up ownership.
§Safety
Think twice before using this. Pointers to dynamically allocated attributes within Self
are copied and will become dangling pointers when self is dropped.
This function is necessary because some functions in open62541 take arguments by value
instead of by pointer without taking ownership and make the caller responsible for
cleaning up after the call has returned.
Sourceunsafe fn as_ref(&self) -> &Self::Inner
unsafe fn as_ref(&self) -> &Self::Inner
Returns shared reference to value.
§Safety
The value is owned by Self. Ownership must not be given away, in whole or in parts. This
may happen when open62541 functions are called that take ownership of values by pointer.
Sourceunsafe fn as_mut(&mut self) -> &mut Self::Inner
unsafe fn as_mut(&mut self) -> &mut Self::Inner
Returns exclusive reference to value.
§Safety
The value is owned by Self. Ownership must not be given away, in whole or in parts. This
may happen when open62541 functions are called that take ownership of values by pointer.
Sourceunsafe fn as_ptr(&self) -> *const Self::Inner
unsafe fn as_ptr(&self) -> *const Self::Inner
Returns const pointer to value.
§Safety
The value is owned by Self. Ownership must not be given away, in whole or in parts. This
may happen when open62541 functions are called that take ownership of values by pointer.
Sourceunsafe fn as_mut_ptr(&mut self) -> *mut Self::Inner
unsafe fn as_mut_ptr(&mut self) -> *mut Self::Inner
Returns mutable pointer to value.
§Safety
The value is owned by Self. Ownership must not be given away, in whole or in parts. This
may happen when open62541 functions are called that take ownership of values by pointer.
Sourcefn print(this: &Self) -> Option<String>
fn print(this: &Self) -> Option<String>
Prints value to string.
This uses UA_print() to generate the string representation.
§Note
The string representation is not guaranteed to be stable across versions.
Sourcefn order(this: &Self, other: &Self) -> UA_Order
fn order(this: &Self, other: &Self) -> UA_Order
Compares value to other.
This uses UA_order() to derive a total ordering between values.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.