pub struct Variant(/* private fields */);Expand description
A Variant can represent many of godot’s core types.
The underlying data can be either stored inline or reference-counted, dependning on the size of the type and whether the it is trivially copyable.
Implementations§
Source§impl Variant
impl Variant
Sourcepub fn from_vector2(val: &TypedVector2D<f32, UnknownUnit>) -> Variant
pub fn from_vector2(val: &TypedVector2D<f32, UnknownUnit>) -> Variant
Creates a Variant wrapping a Vector2.
Sourcepub fn from_vector3(val: &TypedVector3D<f32, UnknownUnit>) -> Variant
pub fn from_vector3(val: &TypedVector3D<f32, UnknownUnit>) -> Variant
Creates a Variant wrapping a Vector3.
Sourcepub fn from_quat(
val: &TypedRotation3D<f32, UnknownUnit, UnknownUnit>,
) -> Variant
pub fn from_quat( val: &TypedRotation3D<f32, UnknownUnit, UnknownUnit>, ) -> Variant
Creates a Variant wrapping a Quat.
Sourcepub fn from_plane(val: &Plane) -> Variant
pub fn from_plane(val: &Plane) -> Variant
Creates a Variant wrapping a Plane.
Sourcepub fn from_rect2(val: &TypedRect<f32>) -> Variant
pub fn from_rect2(val: &TypedRect<f32>) -> Variant
Creates a Variant wrapping a Rect2.
Sourcepub fn from_transform(val: &Transform) -> Variant
pub fn from_transform(val: &Transform) -> Variant
Creates a Variant wrapping a Transform.
Sourcepub fn from_transform2d(
val: &TypedTransform2D<f32, UnknownUnit, UnknownUnit>,
) -> Variant
pub fn from_transform2d( val: &TypedTransform2D<f32, UnknownUnit, UnknownUnit>, ) -> Variant
Creates a Variant wrapping a Transform2D.
Sourcepub fn from_basis(val: &Basis) -> Variant
pub fn from_basis(val: &Basis) -> Variant
Creates a Variant wrapping a Basis.
Sourcepub fn from_color(val: &Color) -> Variant
pub fn from_color(val: &Color) -> Variant
Creates a Variant wrapping a Color.
Sourcepub fn from_node_path(val: &NodePath) -> Variant
pub fn from_node_path(val: &NodePath) -> Variant
Creates a Variant wrapping a NodePath.
Sourcepub fn from_godot_string(val: &GodotString) -> Variant
pub fn from_godot_string(val: &GodotString) -> Variant
Creates a Variant wrapping a GodotString.
Sourcepub fn from_array(val: &VariantArray) -> Variant
pub fn from_array(val: &VariantArray) -> Variant
Creates an Variant wrapping an array of variants.
Sourcepub fn from_byte_array(val: &ByteArray) -> Variant
pub fn from_byte_array(val: &ByteArray) -> Variant
Creates a Variant wrapping a byte array.
Sourcepub fn from_int32_array(val: &Int32Array) -> Variant
pub fn from_int32_array(val: &Int32Array) -> Variant
Creates a Variant wrapping an array of 32bit signed integers.
Sourcepub fn from_float32_array(val: &Float32Array) -> Variant
pub fn from_float32_array(val: &Float32Array) -> Variant
Creates a Variant wrapping an array of 32bit floats.
Sourcepub fn from_string_array(val: &StringArray) -> Variant
pub fn from_string_array(val: &StringArray) -> Variant
Creates a Variant wrapping an array of godot strings.
Sourcepub fn from_vector2_array(val: &Vector2Array) -> Variant
pub fn from_vector2_array(val: &Vector2Array) -> Variant
Creates a Variant wrapping an array of 2d vectors.
Sourcepub fn from_vector3_array(val: &Vector3Array) -> Variant
pub fn from_vector3_array(val: &Vector3Array) -> Variant
Creates a Variant wrapping an array of 3d vectors.
Sourcepub fn from_color_array(val: &ColorArray) -> Variant
pub fn from_color_array(val: &ColorArray) -> Variant
Creates a Variant wrapping an array of colors.
Sourcepub fn from_dictionary(val: &Dictionary) -> Variant
pub fn from_dictionary(val: &Dictionary) -> Variant
Creates a Variant wrapping a dictionary.
Sourcepub fn from_object<T>(val: &T) -> Variantwhere
T: GodotObject,
pub fn from_object<T>(val: &T) -> Variantwhere
T: GodotObject,
Creates a Variant wrapping a Godot object.
Sourcepub fn to_vector2(&self) -> TypedVector2D<f32, UnknownUnit>
pub fn to_vector2(&self) -> TypedVector2D<f32, UnknownUnit>
Do a best effort to create a Vector2 out of the variant, possibly returning a default value.
Sourcepub fn try_to_vector2(&self) -> Option<TypedVector2D<f32, UnknownUnit>>
pub fn try_to_vector2(&self) -> Option<TypedVector2D<f32, UnknownUnit>>
Returns Some(Vector2) if this variant is one, None otherwise.
Sourcepub fn to_vector3(&self) -> TypedVector3D<f32, UnknownUnit>
pub fn to_vector3(&self) -> TypedVector3D<f32, UnknownUnit>
Do a best effort to create a Vector3 out of the variant, possibly returning a default value.
Sourcepub fn try_to_vector3(&self) -> Option<TypedVector3D<f32, UnknownUnit>>
pub fn try_to_vector3(&self) -> Option<TypedVector3D<f32, UnknownUnit>>
Returns Some(Vector3) if this variant is one, None otherwise.
Sourcepub fn to_quat(&self) -> TypedRotation3D<f32, UnknownUnit, UnknownUnit>
pub fn to_quat(&self) -> TypedRotation3D<f32, UnknownUnit, UnknownUnit>
Do a best effort to create a Quat out of the variant, possibly returning a default value.
Sourcepub fn try_to_quat(
&self,
) -> Option<TypedRotation3D<f32, UnknownUnit, UnknownUnit>>
pub fn try_to_quat( &self, ) -> Option<TypedRotation3D<f32, UnknownUnit, UnknownUnit>>
Returns Some(Quat) if this variant is one, None otherwise.
Sourcepub fn to_plane(&self) -> Plane
pub fn to_plane(&self) -> Plane
Do a best effort to create a Plane out of the variant, possibly returning a default value.
Sourcepub fn try_to_plane(&self) -> Option<Plane>
pub fn try_to_plane(&self) -> Option<Plane>
Returns Some(Plane) if this variant is one, None otherwise.
Sourcepub fn to_rect2(&self) -> TypedRect<f32>
pub fn to_rect2(&self) -> TypedRect<f32>
Do a best effort to create a Rect2 out of the variant, possibly returning a default value.
Sourcepub fn try_to_rect2(&self) -> Option<TypedRect<f32>>
pub fn try_to_rect2(&self) -> Option<TypedRect<f32>>
Returns Some(Rect2) if this variant is one, None otherwise.
Sourcepub fn to_transform(&self) -> Transform
pub fn to_transform(&self) -> Transform
Do a best effort to create a Transform out of the variant, possibly returning a default value.
Sourcepub fn try_to_transform(&self) -> Option<Transform>
pub fn try_to_transform(&self) -> Option<Transform>
Returns Some(Transform) if this variant is one, None otherwise.
Sourcepub fn to_transform2d(&self) -> TypedTransform2D<f32, UnknownUnit, UnknownUnit>
pub fn to_transform2d(&self) -> TypedTransform2D<f32, UnknownUnit, UnknownUnit>
Do a best effort to create a Transform2D out of the variant, possibly returning a default value.
Sourcepub fn try_to_transform2d(
&self,
) -> Option<TypedTransform2D<f32, UnknownUnit, UnknownUnit>>
pub fn try_to_transform2d( &self, ) -> Option<TypedTransform2D<f32, UnknownUnit, UnknownUnit>>
Returns Some(Transform2D) if this variant is one, None otherwise.
Sourcepub fn to_basis(&self) -> Basis
pub fn to_basis(&self) -> Basis
Do a best effort to create a Basis out of the variant, possibly returning a default value.
Sourcepub fn try_to_basis(&self) -> Option<Basis>
pub fn try_to_basis(&self) -> Option<Basis>
Returns Some(Basis) if this variant is one, None otherwise.
Sourcepub fn to_color(&self) -> Color
pub fn to_color(&self) -> Color
Do a best effort to create a Color out of the variant, possibly returning a default value.
Sourcepub fn try_to_color(&self) -> Option<Color>
pub fn try_to_color(&self) -> Option<Color>
Returns Some(Color) if this variant is one, None otherwise.
Sourcepub fn to_aabb(&self) -> Aabb
pub fn to_aabb(&self) -> Aabb
Do a best effort to create an Aabb out of the variant, possibly returning a default value.
Sourcepub fn try_to_aabb(&self) -> Option<Aabb>
pub fn try_to_aabb(&self) -> Option<Aabb>
Returns Some(Aabb) if this variant is one, None otherwise.
Sourcepub fn to_f64(&self) -> f64
pub fn to_f64(&self) -> f64
Do a best effort to create a f64 out of the variant, possibly returning a default value.
Sourcepub fn try_to_f64(&self) -> Option<f64>
pub fn try_to_f64(&self) -> Option<f64>
Returns Some(f64) if this variant is one, None otherwise.
Sourcepub fn to_i64(&self) -> i64
pub fn to_i64(&self) -> i64
Do a best effort to create an i64 out of the variant, possibly returning a default value.
Sourcepub fn try_to_i64(&self) -> Option<i64>
pub fn try_to_i64(&self) -> Option<i64>
Returns Some(i64) if this variant is one, None otherwise.
Sourcepub fn to_bool(&self) -> bool
pub fn to_bool(&self) -> bool
Do a best effort to create a bool out of the variant, possibly returning a default value.
Sourcepub fn try_to_bool(&self) -> Option<bool>
pub fn try_to_bool(&self) -> Option<bool>
Returns Some(bool) if this variant is one, None otherwise.
Sourcepub fn to_node_path(&self) -> NodePath
pub fn to_node_path(&self) -> NodePath
Do a best effort to create a NodePath out of the variant, possibly returning a default value.
Sourcepub fn try_to_node_path(&self) -> Option<NodePath>
pub fn try_to_node_path(&self) -> Option<NodePath>
Returns Some(NodePath) if this variant is one, None otherwise.
Sourcepub fn to_godot_string(&self) -> GodotString
pub fn to_godot_string(&self) -> GodotString
Do a best effort to create a GodotString out of the variant, possibly returning a default value.
Sourcepub fn try_to_godot_string(&self) -> Option<GodotString>
pub fn try_to_godot_string(&self) -> Option<GodotString>
Returns Some(GodotString) if this variant is one, None otherwise.
Sourcepub fn to_rid(&self) -> Rid
pub fn to_rid(&self) -> Rid
Do a best effort to create a Rid out of the variant, possibly returning a default value.
Sourcepub fn try_to_rid(&self) -> Option<Rid>
pub fn try_to_rid(&self) -> Option<Rid>
Returns Some(Rid) if this variant is one, None otherwise.
Sourcepub fn to_array(&self) -> VariantArray
pub fn to_array(&self) -> VariantArray
Do a best effort to create a VariantArray out of the variant, possibly returning a default value.
Sourcepub fn try_to_array(&self) -> Option<VariantArray>
pub fn try_to_array(&self) -> Option<VariantArray>
Returns Some(VariantArray) if this variant is one, None otherwise.
Sourcepub fn to_byte_array(&self) -> ByteArray
pub fn to_byte_array(&self) -> ByteArray
Do a best effort to create a ByteArray out of the variant, possibly returning a default value.
Sourcepub fn try_to_byte_array(&self) -> Option<ByteArray>
pub fn try_to_byte_array(&self) -> Option<ByteArray>
Returns Some(ByteArray) if this variant is one, None otherwise.
Sourcepub fn to_int32_array(&self) -> Int32Array
pub fn to_int32_array(&self) -> Int32Array
Do a best effort to create an Int32Array out of the variant, possibly returning a default value.
Sourcepub fn try_to_int32_array(&self) -> Option<Int32Array>
pub fn try_to_int32_array(&self) -> Option<Int32Array>
Returns Some(Int32Array) if this variant is one, None otherwise.
Sourcepub fn to_float32_array(&self) -> Float32Array
pub fn to_float32_array(&self) -> Float32Array
Do a best effort to create a Float32Array out of the variant, possibly returning a default value.
Sourcepub fn try_to_float32_array(&self) -> Option<Float32Array>
pub fn try_to_float32_array(&self) -> Option<Float32Array>
Returns Some(Float32Array) if this variant is one, None otherwise.
Sourcepub fn to_string_array(&self) -> StringArray
pub fn to_string_array(&self) -> StringArray
Do a best effort to create a StringArray out of the variant, possibly returning a default value.
Sourcepub fn try_to_string_array(&self) -> Option<StringArray>
pub fn try_to_string_array(&self) -> Option<StringArray>
Returns Some(StringArray) if this variant is one, None otherwise.
Sourcepub fn to_vector2_array(&self) -> Vector2Array
pub fn to_vector2_array(&self) -> Vector2Array
Do a best effort to create a Vector2Array out of the variant, possibly returning a default value.
Sourcepub fn try_to_vector2_array(&self) -> Option<Vector2Array>
pub fn try_to_vector2_array(&self) -> Option<Vector2Array>
Returns Some(Vector2Array) if this variant is one, None otherwise.
Sourcepub fn to_vector3_array(&self) -> Vector3Array
pub fn to_vector3_array(&self) -> Vector3Array
Do a best effort to create a Vector3Array out of the variant, possibly returning a default value.
Sourcepub fn try_to_vector3_array(&self) -> Option<Vector3Array>
pub fn try_to_vector3_array(&self) -> Option<Vector3Array>
Returns Some(Vector3Array) if this variant is one, None otherwise.
Sourcepub fn to_color_array(&self) -> ColorArray
pub fn to_color_array(&self) -> ColorArray
Do a best effort to create a ColorArray out of the variant, possibly returning a default value.
Sourcepub fn try_to_color_array(&self) -> Option<ColorArray>
pub fn try_to_color_array(&self) -> Option<ColorArray>
Returns Some(ColorArray) if this variant is one, None otherwise.
Sourcepub fn to_dictionary(&self) -> Dictionary
pub fn to_dictionary(&self) -> Dictionary
Do a best effort to create a Dictionary out of the variant, possibly returning a default value.
Sourcepub fn try_to_dictionary(&self) -> Option<Dictionary>
pub fn try_to_dictionary(&self) -> Option<Dictionary>
Returns Some(Dictionary) if this variant is one, None otherwise.
pub fn try_to_object<T>(&self) -> Option<T>where
T: GodotObject,
pub fn to_string(&self) -> String
pub fn try_to_string(&self) -> Option<String>
Sourcepub fn get_type(&self) -> VariantType
pub fn get_type(&self) -> VariantType
Returns this variant’s type.
pub fn has_method(&self, method: &GodotString) -> bool
pub fn call(&mut self, method: &GodotString, args: &[Variant]) -> Result<(), ()>
Sourcepub fn forget(self) -> godot_variant
pub fn forget(self) -> godot_variant
Returns the internal ffi representation of the variant and consumes the rust object without running the destructor.
This should be only used when certain that the receiving side is responsible for running the destructor for the object, otherwise it is leaked.