From 06e93ba3fd5832f260d59dc097b669c411d6ac5e Mon Sep 17 00:00:00 2001 From: Danny McGee Date: Tue, 19 Dec 2023 17:37:13 -0500 Subject: [PATCH] Fix type mismatch --- studio-bvh/src/joint.rs | 18 +++++++++++++++++- studio-bvh/src/macros.rs | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/studio-bvh/src/joint.rs b/studio-bvh/src/joint.rs index 08339c0..9c35966 100644 --- a/studio-bvh/src/joint.rs +++ b/studio-bvh/src/joint.rs @@ -1,7 +1,7 @@ #![allow(dead_code, missing_docs)] use crate::Channel; -use bstr::{BStr, BString, ByteSlice}; +use bstr::{BStr, BString, ByteSlice, Utf8Error}; use smallvec::SmallVec; use std::{ cmp::{Ordering, PartialEq, PartialOrd}, @@ -62,6 +62,16 @@ impl JointData { name.as_bytes() } + #[inline] + pub(crate) fn name_str(&self) -> Result<&str, Utf8Error> { + let name = match *self { + JointData::Root { ref name, .. } => name, + JointData::Child { ref name, .. } => name, + }; + + name.as_str() + } + #[inline] pub(crate) const fn offset(&self) -> &Offset { match *self { @@ -213,9 +223,15 @@ pub(crate) type JointNameInner = SmallVec<[u8; mem::size_of::()]>; pub(crate) struct JointName(pub(crate) JointNameInner); impl JointName { + #[inline] pub(crate) fn as_bytes(&self) -> &[u8] { self.as_ref() } + + #[inline] + pub(crate) fn as_str(&self) -> Result<&str, Utf8Error> { + self.as_bytes().to_str() + } } impl Deref for JointName { diff --git a/studio-bvh/src/macros.rs b/studio-bvh/src/macros.rs index ed9b305..5c8ba68 100644 --- a/studio-bvh/src/macros.rs +++ b/studio-bvh/src/macros.rs @@ -535,7 +535,11 @@ mod tests { channels: &[ChannelType], end_site: O, ) { - assert_eq!(joint.name(), expected_name); + let name = match joint.name_str() { + Ok(name) => name, + Err(err) => panic!("{err}"), + }; + assert_eq!(name, expected_name); assert_eq!(*joint.offset(), expected_offset); for (chan, expected_chan) in joint .channels()