Variant

Enum Variant 

Source
pub enum Variant {
Show 27 variants Empty, Boolean(bool), SByte(i8), Byte(u8), Int16(i16), UInt16(u16), Int32(i32), UInt32(u32), Int64(i64), UInt64(u64), Float(f32), Double(f64), String(UAString), DateTime(Box<DateTime>), Guid(Box<Guid>), StatusCode(StatusCode), ByteString(ByteString), XmlElement(XmlElement), QualifiedName(Box<QualifiedName>), LocalizedText(Box<LocalizedText>), NodeId(Box<NodeId>), ExpandedNodeId(Box<ExpandedNodeId>), ExtensionObject(ExtensionObject), Variant(Box<Variant>), DataValue(Box<DataValue>), DiagnosticInfo(Box<DiagnosticInfo>), Array(Box<Array>),
}
Expand description

A Variant holds built-in OPC UA data types, including single and multi dimensional arrays, data values and extension objects.

As variants may be passed around a lot on the stack, Boxes are used for more complex types to keep the size of this type down a bit, especially when used in arrays.

Variants§

§

Empty

Empty type has no value. It is equivalent to a Null value (part 6 5.1.6)

§

Boolean(bool)

Boolean

§

SByte(i8)

Signed byte

§

Byte(u8)

Unsigned byte

§

Int16(i16)

Signed 16-bit int

§

UInt16(u16)

Unsigned 16-bit int

§

Int32(i32)

Signed 32-bit int

§

UInt32(u32)

Unsigned 32-bit int

§

Int64(i64)

Signed 64-bit int

§

UInt64(u64)

Unsigned 64-bit int

§

Float(f32)

Float

§

Double(f64)

Double

§

String(UAString)

String

§

DateTime(Box<DateTime>)

DateTime

§

Guid(Box<Guid>)

Guid

§

StatusCode(StatusCode)

StatusCode

§

ByteString(ByteString)

ByteString

§

XmlElement(XmlElement)

XmlElement

§

QualifiedName(Box<QualifiedName>)

QualifiedName

§

LocalizedText(Box<LocalizedText>)

LocalizedText

§

NodeId(Box<NodeId>)

NodeId

§

ExpandedNodeId(Box<ExpandedNodeId>)

ExpandedNodeId

§

ExtensionObject(ExtensionObject)

ExtensionObject

§

Variant(Box<Variant>)

Variant containing a nested variant.

§

DataValue(Box<DataValue>)

DataValue

§

DiagnosticInfo(Box<DiagnosticInfo>)

DiagnosticInfo

§

Array(Box<Array>)

Single dimension array which can contain any scalar type, all the same type. Nested arrays will be rejected. To represent matrices or nested arrays, set the array_dimensions field on the Array.

Implementations§

Source§

impl Variant

Source

pub fn serialize_variant_value( &self, stream: &mut JsonStreamWriter<&mut dyn Write>, ctx: &Context<'_>, ) -> EncodingResult<()>

JSON serialize the value of a variant using OPC-UA JSON encoding.

Note that this serializes just the value. To include the type ID, use JsonEncodable::encode.

Source§

impl Variant

Source

pub fn get_variant_default(ty: VariantScalarTypeId) -> Variant

Get a default variant of the given type.

Source

pub fn xml_decode_variant_value( stream: &mut XmlStreamReader<&mut dyn Read>, context: &Context<'_>, key: &str, ) -> EncodingResult<Self>

Decode an XML variant value from stream, consuming the rest of the current element.

Source§

impl Variant

Source

pub fn value_byte_len(&self, ctx: &Context<'_>) -> usize

Get the value in bytes of the contents of this variant if it is serialize to OPC-UA binary.

To get the full byte length including type ID, use BinaryEncodable::encode

Source

pub fn encode_value<S: Write + ?Sized>( &self, stream: &mut S, ctx: &Context<'_>, ) -> EncodingResult<()>

Encode the value of this variant as binary to the given stream.

Note that to encode a full variant with type ID and other details, use BinaryEncodable::encode

Source§

impl Variant

Source

pub fn test_encoding_flag(encoding_mask: u8, flag: u8) -> bool

Test the flag (convenience method)

Source

pub fn cast<'a>(&self, target_type: impl Into<VariantTypeId<'a>>) -> Variant

Performs an EXPLICIT cast from one type to another. This will first attempt an implicit conversion and only then attempt to cast. Casting is potentially lossy.

Source

pub fn convert<'a>(&self, target_type: impl Into<VariantTypeId<'a>>) -> Variant

Performs an IMPLICIT conversion from one type to another

Source

pub fn type_id(&self) -> VariantTypeId<'_>

Get the type ID of this variant. This can be useful to work with the variant abstractly, and check if the variant is of the expected type and dimensions.

Source

pub fn scalar_type_id(&self) -> Option<VariantScalarTypeId>

Get the scalar type id of this variant, if present.

This returns None only if the variant is empty.

Source

pub fn is_empty(&self) -> bool

Returns true if this variant is Variant::Empty.

Source

pub fn is_numeric(&self) -> bool

Tests and returns true if the variant holds a numeric type

Source

pub fn is_array(&self) -> bool

Test if the variant holds an array

Source

pub fn as_array(&self) -> Option<&Vec<Variant>>

Try to get the inner array if this is an array variant.

Source

pub fn is_array_of_type(&self, variant_type: VariantScalarTypeId) -> bool

Check if this is an array of the given variant type.

Source

pub fn is_valid(&self) -> bool

Tests that the variant is in a valid state. In particular for arrays ensuring that the values are all acceptable and for a multi dimensional array that the dimensions equal the actual values.

Source

pub fn as_f64(&self) -> Option<f64>

Converts the numeric type to a double or returns None

Source

pub fn data_type(&self) -> Option<ExpandedNodeId>

Returns the scalar data type. Returns None if the variant is Empty.

Source

pub fn to_byte_array(&self) -> Result<Self, ArrayError>

This function is for a special edge case of converting a byte string to a single array of bytes

Source

pub fn set_range_of( &mut self, range: &NumericRange, other: &Variant, ) -> Result<(), StatusCode>

Set a range of values in this variant using a different variant.

Source

pub fn range_of_owned(self, range: &NumericRange) -> Result<Variant, StatusCode>

This function gets a range of values from the variant if it is an array, or returns the variant itself.

Source

pub fn range_of(&self, range: &NumericRange) -> Result<Variant, StatusCode>

This function gets a range of values from the variant if it is an array, or returns a clone of the variant itself.

Source

pub fn try_cast_to<T: TryFromVariant>(self) -> Result<T, Error>

Try to cast this variant to the type T.

Source§

impl Variant

Source

pub fn from_nodeset( val: &XmlVariant, ctx: &Context<'_>, ) -> EncodingResult<Variant>

Create a Variant value from a NodeSet2 variant object. Note that this is different from the FromXml implementation of Variant, which accepts an untyped XML node.

Trait Implementations§

Source§

impl BinaryDecodable for Variant

Source§

fn decode<S: Read + ?Sized>( stream: &mut S, ctx: &Context<'_>, ) -> EncodingResult<Self>

Decodes an instance from the read stream. The decoding options contains restrictions set by the server / client on the length of strings, arrays etc. If these limits are exceeded the implementation should return with a BadDecodingError as soon as possible.
Source§

impl BinaryEncodable for Variant

Source§

fn byte_len(&self, ctx: &Context<'_>) -> usize

Returns the exact byte length of the structure as it would be if encode were called. This may be called prior to writing to ensure the correct amount of space is available.
Source§

fn encode<S: Write + ?Sized>( &self, stream: &mut S, ctx: &Context<'_>, ) -> EncodingResult<()>

Encodes the instance to the write stream.
Source§

fn override_encoding(&self) -> Option<BuiltInDataEncoding>

Override the extension object encoding used for this type. This only makes sense if the type can only ever be encoded using a single built-in encoding.
Source§

fn encode_to_vec(&self, ctx: &Context<'_>) -> Vec<u8>

Convenience method for encoding a message straight into an array of bytes. It is preferable to reuse buffers than to call this so it should be reserved for tests and trivial code.
Source§

impl Clone for Variant

Source§

fn clone(&self) -> Variant

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 Debug for Variant

Source§

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

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

impl Default for Variant

Source§

fn default() -> Variant

Returns the “default value” for a type. Read more
Source§

impl Display for Variant

This implementation is mainly for debugging / convenience purposes, to eliminate some of the noise in common types from using the Debug trait.

Source§

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

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

impl EventField for Variant

Source§

fn get_value( &self, attribute_id: AttributeId, index_range: &NumericRange, remaining_path: &[QualifiedName], ) -> Variant

Get the variant representation of this field, using the given index range. Read more
Source§

impl<'a, T> From<&'a [T]> for Variant
where T: Into<Variant> + VariantType + Clone,

Source§

fn from(value: &'a [T]) -> Self

Converts to this type from the input type.
Source§

impl<'a, T> From<&'a Vec<T>> for Variant
where T: Into<Variant> + VariantType + Clone,

Source§

fn from(value: &'a Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Variant

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl<'a, 'b> From<(VariantScalarTypeId, &'a [&'b str])> for Variant

Source§

fn from(v: (VariantScalarTypeId, &'a [&'b str])) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Variant>> From<(VariantScalarTypeId, Vec<T>)> for Variant

Source§

fn from(v: (VariantScalarTypeId, Vec<T>)) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Variant>> From<(VariantScalarTypeId, Vec<T>, Vec<u32>)> for Variant

Source§

fn from(v: (VariantScalarTypeId, Vec<T>, Vec<u32>)) -> Self

Converts to this type from the input type.
Source§

impl From<DataTypeDefinition> for Variant

Source§

fn from(value: DataTypeDefinition) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for Variant
where T: Into<Variant>,

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Variant
where T: IntoVariant,

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl From<Variant> for DataValue

Source§

fn from(v: Variant) -> Self

Converts to this type from the input type.
Source§

impl From<Variant> for LiteralOperand

Source§

fn from(v: Variant) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Variant
where T: Into<Variant> + VariantType,

Source§

fn from(value: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl JsonDecodable for Variant

Source§

fn decode( stream: &mut JsonStreamReader<&mut dyn Read>, ctx: &Context<'_>, ) -> EncodingResult<Self>

Decode Self from a JSON stream.
Source§

impl JsonEncodable for Variant

Source§

fn encode( &self, stream: &mut JsonStreamWriter<&mut dyn Write>, ctx: &Context<'_>, ) -> EncodingResult<()>

Write the type to the provided JSON writer.
Source§

impl PartialEq for Variant

Source§

fn eq(&self, other: &Variant) -> 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 TryFromVariant for Variant

Source§

fn try_from_variant(v: Variant) -> Result<Self, Error>

Try to cast the given variant to this type.
Source§

impl UaNullable for Variant

Source§

fn is_ua_null(&self) -> bool

Return true if this value is null, meaning it can be left out when being encoded in JSON and XML encodings.
Source§

impl VariantType for Variant

Source§

fn variant_type_id() -> VariantScalarTypeId

The variant kind this type will be represented as.
Source§

impl XmlDecodable for Variant

Source§

fn decode( stream: &mut XmlStreamReader<&mut dyn Read>, context: &Context<'_>, ) -> Result<Self, Error>

Decode a value from an XML stream.
Source§

impl XmlEncodable for Variant

Source§

fn encode( &self, stream: &mut XmlStreamWriter<&mut dyn Write>, ctx: &Context<'_>, ) -> EncodingResult<()>

Encode a value to an XML stream.
Source§

impl XmlType for Variant

Source§

const TAG: &'static str = "Variant"

The static fallback tag for this type. Convenience feature, but also used in nested types.
Source§

fn tag(&self) -> &str

The XML tag name for this type.
Source§

impl StructuralPartialEq for Variant

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more