Fix type mismatch

This commit is contained in:
Danny McGee
2023-12-19 17:37:13 -05:00
parent 15fd44d7e0
commit 06e93ba3fd
2 changed files with 22 additions and 2 deletions
+17 -1
View File
@@ -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::<String>()]>;
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 {
+5 -1
View File
@@ -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()