Skip to content

Commit

Permalink
feat: impl PartialEq against strings w/ standard bones & blend shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
decahedron1 committed Aug 11, 2023
1 parent a114476 commit b565307
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,27 @@ impl FromStr for StandardVRM0Bone {
}
}

impl PartialEq<&str> for StandardVRM0Bone {
fn eq(&self, other: &&str) -> bool {
StandardVRM0Bone::from_str(other).as_ref() == Ok(self)
}
}
impl PartialEq<String> for StandardVRM0Bone {
fn eq(&self, other: &String) -> bool {
StandardVRM0Bone::from_str(other).as_ref() == Ok(self)
}
}
impl PartialEq<StandardVRM0Bone> for &str {
fn eq(&self, other: &StandardVRM0Bone) -> bool {
StandardVRM0Bone::from_str(self).as_ref() == Ok(other)
}
}
impl PartialEq<StandardVRM0Bone> for String {
fn eq(&self, other: &StandardVRM0Bone) -> bool {
StandardVRM0Bone::from_str(self).as_ref() == Ok(other)
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct BoneTransform {
pub bone: String,
Expand Down Expand Up @@ -448,6 +469,27 @@ impl FromStr for StandardVRMBlendShape {
}
}

impl PartialEq<&str> for StandardVRMBlendShape {
fn eq(&self, other: &&str) -> bool {
StandardVRMBlendShape::from_str(other).as_ref() == Ok(self)
}
}
impl PartialEq<String> for StandardVRMBlendShape {
fn eq(&self, other: &String) -> bool {
StandardVRMBlendShape::from_str(other).as_ref() == Ok(self)
}
}
impl PartialEq<StandardVRMBlendShape> for &str {
fn eq(&self, other: &StandardVRMBlendShape) -> bool {
StandardVRMBlendShape::from_str(self).as_ref() == Ok(other)
}
}
impl PartialEq<StandardVRMBlendShape> for String {
fn eq(&self, other: &StandardVRMBlendShape) -> bool {
StandardVRMBlendShape::from_str(self).as_ref() == Ok(other)
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct BlendShape {
pub key: String,
Expand Down Expand Up @@ -1019,7 +1061,7 @@ mod tests {
let parsed_packet = &parse(packet)?[0];
match parsed_packet {
VMCMessage::BoneTransform(transform) => {
assert_eq!(transform.bone, bone.to_string());
assert_eq!(transform.bone, bone);
assert_relative_eq!(transform.position, position);
assert_relative_eq!(transform.rotation, rotation);
assert!(transform.scale.is_none());
Expand All @@ -1032,7 +1074,7 @@ mod tests {
let parsed_packet = &parse(packet)?[0];
match parsed_packet {
VMCMessage::BoneTransform(transform) => {
assert_eq!(transform.bone, bone.to_string());
assert_eq!(transform.bone, bone);
assert_relative_eq!(transform.position, position);
assert_relative_eq!(transform.rotation, rotation);
assert_relative_eq!(transform.scale.unwrap(), scale);
Expand Down

0 comments on commit b565307

Please sign in to comment.