Trait gdnative_core::core_types::FromVariant
source · pub trait FromVariant: Sized {
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>;
}
Expand description
Types that can be converted from a Variant
. Conversions are performed in Rust, and can be
implemented for custom types.
FromVariant
generally avoids inexact conversions, favoring returning an error instead,
with the noted exception of integer and float types that are not supported by Godot natively.
This is stricter than what GDScript performs by default. For weakly-typed coercions of GDScript
built-in typed, see CoerceFromVariant
instead.
This trait is used for argument types of exported methods.
Option<T>
and MaybeNot<T>
Option<T>
requires the Variant to be T
or Nil
, in that order. For looser semantics,
use MaybeNot<T>
, which will catch all variant values that are not T
as well.
Vec<T>
The FromVariant
implementation for Vec<T>
only allow homogeneous arrays. If you want to
manually handle potentially heterogeneous values e.g. for error reporting, use VariantArray
directly or compose with an appropriate wrapper: Vec<Option<T>>
or Vec<MaybeNot<T>>
.
Deriving FromVariant
The derive macro provides implementation consistent with derived ToVariant
. See ToVariant
for detailed documentation.
Required Methods§
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
Implementations on Foreign Types§
source§impl FromVariant for ()
impl FromVariant for ()
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for f64
impl FromVariant for f64
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for i64
impl FromVariant for i64
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for u64
impl FromVariant for u64
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for bool
impl FromVariant for bool
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for i8
impl FromVariant for i8
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for i16
impl FromVariant for i16
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for i32
impl FromVariant for i32
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for isize
impl FromVariant for isize
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for u8
impl FromVariant for u8
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for u16
impl FromVariant for u16
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for u32
impl FromVariant for u32
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for usize
impl FromVariant for usize
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for f32
impl FromVariant for f32
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl FromVariant for String
impl FromVariant for String
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl<T> FromVariant for PhantomData<T>
impl<T> FromVariant for PhantomData<T>
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl<T: FromVariant> FromVariant for Option<T>
impl<T: FromVariant> FromVariant for Option<T>
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl<T: FromVariant, E: FromVariant> FromVariant for Result<T, E>
impl<T: FromVariant, E: FromVariant> FromVariant for Result<T, E>
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl<T: FromVariant> FromVariant for Vec<T>
impl<T: FromVariant> FromVariant for Vec<T>
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl<K: FromVariant + Hash + Eq, V: FromVariant> FromVariant for HashMap<K, V>
impl<K: FromVariant + Hash + Eq, V: FromVariant> FromVariant for HashMap<K, V>
Expects a Variant
populated with a Dictionary
and tries to convert it into a HashMap
.
Since Rust’s HashMap
is unordered, there is no guarantee about the resulting element order.
In fact it is possible that two program invocations cause a different output.
fn from_variant(variant: &Variant) -> Result<Self, FromVariantError>
source§impl<T: FromVariant + Eq + Hash> FromVariant for HashSet<T>
impl<T: FromVariant + Eq + Hash> FromVariant for HashSet<T>
Expects a Variant
populated with a VariantArray
and tries to convert it into a HashSet
.
Since Rust’s HashSet
is unordered, there is no guarantee about the resulting element order.
In fact it is possible that two program invocations cause a different output.