Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/manufacturer specific data record #25

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn parse_to_table(input: &str) -> std::string::String {
};

table.add_row(row![
format!("({}{:}", record.data, value_information),
format!("({}{}", record.data, value_information),
format!("{}", data_information)
]);
}
Expand Down
19 changes: 14 additions & 5 deletions src/user_data/data_information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ impl PartialEq<str> for TextUnit<'_> {
self.0.iter().eq(other.as_bytes().iter().rev())
}
}

#[cfg(feature = "std")]
impl std::fmt::Display for TextUnit<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let value: Vec<u8> = self.0.iter().copied().rev().collect();
let value = String::from_utf8(value).unwrap_or_default();
write!(f, "{}", value)
}
}

#[cfg(any(feature = "serde", feature = "std"))]
impl From<TextUnit<'_>> for String {
fn from(value: TextUnit<'_>) -> Self {
Expand Down Expand Up @@ -366,10 +376,6 @@ impl std::fmt::Display for Data<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.value {
Some(value) => match value {
&DataType::Text(text) => {
let text: String = text.into();
write!(f, "{}", text)
}
DataType::Number(value) => write!(f, "{}", value),
DataType::Date(day, month, year) => write!(f, "{}/{}/{}", day, month, year),
DataType::DateTime(day, month, year, hour, minute) => {
Expand All @@ -385,7 +391,10 @@ impl std::fmt::Display for Data<'_> {
DataType::Time(seconds, minutes, hours) => {
write!(f, "{}:{}:{}", hours, minutes, seconds)
}
DataType::Text(text_unit) => todo!(),
DataType::Text(text_unit) => {
let text: String = (*text_unit).into();
write!(f, "{}", text)
}
DataType::ManufacturerSpecific(data) => {
write!(f, "Manufacturer Specific: {:?}", data)
}
Expand Down