diff --git a/packages/lib-roblox/src/datatypes/vector2.rs b/packages/lib-roblox/src/datatypes/vector2.rs index 084d556..af16b36 100644 --- a/packages/lib-roblox/src/datatypes/vector2.rs +++ b/packages/lib-roblox/src/datatypes/vector2.rs @@ -118,10 +118,22 @@ impl DatatypeTable for Vector2 { } } +impl From<&RbxVector2> for Vector2 { + fn from(v: &RbxVector2) -> Self { + Vector2(Vec2 { x: v.x, y: v.y }) + } +} + +impl From<&Vector2> for RbxVector2 { + fn from(v: &Vector2) -> Self { + RbxVector2 { x: v.0.x, y: v.0.y } + } +} + impl FromRbxVariant for Vector2 { fn from_rbx_variant(variant: &RbxVariant) -> RbxConversionResult { if let RbxVariant::Vector2(v) = variant { - Ok(Vector2(Vec2 { x: v.x, y: v.y })) + Ok(v.into()) } else { Err(RbxConversionError::FromRbxVariant { from: variant.display_name(), @@ -138,10 +150,7 @@ impl ToRbxVariant for Vector2 { desired_type: Option, ) -> RbxConversionResult { if matches!(desired_type, None | Some(RbxVariantType::Vector2)) { - Ok(RbxVariant::Vector2(RbxVector2 { - x: self.0.x, - y: self.0.y, - })) + Ok(RbxVariant::Vector2(self.into())) } else { Err(RbxConversionError::DesiredTypeMismatch { can_convert_to: Some(RbxVariantType::Vector2.display_name()), diff --git a/packages/lib-roblox/src/datatypes/vector3.rs b/packages/lib-roblox/src/datatypes/vector3.rs index f5374d3..32d4b76 100644 --- a/packages/lib-roblox/src/datatypes/vector3.rs +++ b/packages/lib-roblox/src/datatypes/vector3.rs @@ -132,14 +132,30 @@ impl DatatypeTable for Vector3 { } } +impl From<&RbxVector3> for Vector3 { + fn from(v: &RbxVector3) -> Self { + Vector3(Vec3 { + x: v.x, + y: v.y, + z: v.z, + }) + } +} + +impl From<&Vector3> for RbxVector3 { + fn from(v: &Vector3) -> Self { + RbxVector3 { + x: v.0.x, + y: v.0.y, + z: v.0.z, + } + } +} + impl FromRbxVariant for Vector3 { fn from_rbx_variant(variant: &RbxVariant) -> RbxConversionResult { if let RbxVariant::Vector3(v) = variant { - Ok(Vector3(Vec3 { - x: v.x, - y: v.y, - z: v.z, - })) + Ok(v.into()) } else { Err(RbxConversionError::FromRbxVariant { from: variant.display_name(), @@ -156,11 +172,7 @@ impl ToRbxVariant for Vector3 { desired_type: Option, ) -> RbxConversionResult { if matches!(desired_type, None | Some(RbxVariantType::Vector3)) { - Ok(RbxVariant::Vector3(RbxVector3 { - x: self.0.x, - y: self.0.y, - z: self.0.z, - })) + Ok(RbxVariant::Vector3(self.into())) } else { Err(RbxConversionError::DesiredTypeMismatch { can_convert_to: Some(RbxVariantType::Vector3.display_name()),