Skip to content

Commit

Permalink
Remove use of ref to format!(...), compose output instead
Browse files Browse the repository at this point in the history
fmt
  • Loading branch information
TTWNO committed Jun 27, 2024
1 parent f619312 commit 1ad0c1c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
52 changes: 40 additions & 12 deletions atspi-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,56 @@ impl std::fmt::Display for AtspiError {
match self {
Self::Conversion(e) => f.write_str(&format!("atspi: conversion failure: {e}")),
Self::MemberMatch(e) => {
f.write_str(format!("atspi: member mismatch in conversion: {e}").as_str())
f.write_str("atspi: member mismatch in conversion: ")?;
e.fmt(f)

Check warning on line 78 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L77-L78

Added lines #L77 - L78 were not covered by tests
}
Self::InterfaceMatch(e) => {
f.write_str(format!("atspi: interface mismatch in conversion: {e}").as_str())
f.write_str("atspi: interface mismatch in conversion: ")?;
e.fmt(f)

Check warning on line 82 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L81-L82

Added lines #L81 - L82 were not covered by tests
}
Self::UnknownBusSignature(e) => {
f.write_str(format!("atspi: Unknown bus body signature: {e:?}").as_str())
f.write_str("atspi: Unknown bus body signature: ")?;
e.fmt(f)

Check warning on line 86 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L85-L86

Added lines #L85 - L86 were not covered by tests
}
Self::UnknownInterface => f.write_str("Unknown interface."),
Self::MissingInterface => f.write_str("Missing interface."),
Self::MissingMember => f.write_str("Missing member."),
Self::MissingSignature => f.write_str("Missing signature."),
Self::UnknownRole(e) => f.write_str(&format!("atspi: Unknown role: {e}")),
Self::UnknownRole(e) => {
f.write_str("atspi: Unknown role: ")?;
e.fmt(f)

Check warning on line 94 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L92-L94

Added lines #L92 - L94 were not covered by tests
}
Self::UnknownSignal => f.write_str("atspi: Unknown signal"),
Self::CacheVariantMismatch => f.write_str("atspi: Cache variant mismatch"),
Self::Owned(e) => f.write_str(&format!("atspi: other error: {e}")),
Self::Zbus(e) => f.write_str(&format!("ZBus Error: {e}")),
Self::Zvariant(e) => f.write_str(&format!("Zvariant error: {e}")),
Self::ZBusNames(e) => f.write_str(&format!("ZBus_names Error: {e}")),
Self::Owned(e) => {
f.write_str("atspi: other error: ")?;
e.fmt(f)

Check warning on line 100 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L98-L100

Added lines #L98 - L100 were not covered by tests
}
Self::Zbus(e) => {
f.write_str("ZBus Error: ")?;
e.fmt(f)

Check warning on line 104 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L102-L104

Added lines #L102 - L104 were not covered by tests
}
Self::Zvariant(e) => {
f.write_str("Zvariant error: ")?;
e.fmt(f)

Check warning on line 108 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L106-L108

Added lines #L106 - L108 were not covered by tests
}
Self::ZBusNames(e) => {
f.write_str("ZBus_names Error: ")?;
e.fmt(f)

Check warning on line 112 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L110-L112

Added lines #L110 - L112 were not covered by tests
}
Self::ParseError(e) => f.write_str(e),
Self::PathConversionError(e) => {
f.write_str(&format!("ID cannot be extracted from the path: {e}"))
f.write_str("ID cannot be extracted from the path: ")?;
e.fmt(f)

Check warning on line 117 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L116-L117

Added lines #L116 - L117 were not covered by tests
}
Self::IO(e) => {
f.write_str("std IO Error: ")?;
e.fmt(f)

Check warning on line 121 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L119-L121

Added lines #L119 - L121 were not covered by tests
}
Self::IntConversionError(e) => {
f.write_str("Integer conversion error: ")?;
e.fmt(f)

Check warning on line 125 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L123-L125

Added lines #L123 - L125 were not covered by tests
}
Self::IO(e) => f.write_str(&format!("std IO Error: {e}")),
Self::IntConversionError(e) => f.write_str(&format!("Integer conversion error: {e}")),
Self::MissingName => f.write_str("Missing name for a bus."),
Self::Infallible => {
f.write_str("Infallible; only to trick the compiler. This should never happen.")
Expand Down Expand Up @@ -166,7 +191,10 @@ impl std::fmt::Display for ObjectPathConversionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoIdAvailable => f.write_str("No ID available in the path."),
Self::ParseError(e) => f.write_str(&format!("Failure to parse: {e}")),
Self::ParseError(e) => {
f.write_str("Failure to parse: {e}")?;
e.fmt(f)

Check warning on line 196 in atspi-common/src/error.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/error.rs#L194-L196

Added lines #L194 - L196 were not covered by tests
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion atspi-common/src/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ impl Role {

impl std::fmt::Display for Role {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name())
f.write_str(self.name())

Check warning on line 615 in atspi-common/src/role.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/role.rs#L615

Added line #L615 was not covered by tests
}
}

Expand Down

0 comments on commit 1ad0c1c

Please sign in to comment.