Skip to content

Commit 1fa98a5

Browse files
authored
Merge pull request #118 from influxdata/crepererum/fix-ok-and-err-str
fix: `str` representation of `value` of `OkWrapper`/`ErrWrapper`
2 parents 1ff713d + fe9a9c8 commit 1fa98a5

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

guests/python/src/python_modules/error.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ macro_rules! display_like_debug {
1414

1515
pub(crate) use display_like_debug;
1616

17+
/// Wrapper that forwards [`Debug`](std::fmt::Debug) to [`Display`](std::fmt::Display).
18+
pub(crate) struct DebugLikeDisplay<T>(pub(crate) T)
19+
where
20+
T: std::fmt::Display;
21+
22+
impl<T> std::fmt::Debug for DebugLikeDisplay<T>
23+
where
24+
T: std::fmt::Display,
25+
{
26+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27+
self.0.fmt(f)
28+
}
29+
}
30+
1731
/// A resource (handle) was already used/moved/closed.
1832
#[derive(Debug, Default, Clone, Copy)]
1933
pub(crate) struct ResourceMoved;

guests/python/src/python_modules/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use pyo3::{BoundObject, exceptions::PyValueError, prelude::*};
33

44
mod error;
55

6-
use error::{ResourceMoved, ResourceMovedOptionExt, display_like_debug};
6+
use error::{DebugLikeDisplay, ResourceMoved, ResourceMovedOptionExt, display_like_debug};
77

88
/// Register python modules.
99
///
@@ -1536,6 +1536,7 @@ mod wit_world {
15361536

15371537
#[pyo3::pymodule]
15381538
pub(crate) mod types {
1539+
15391540
use super::*;
15401541

15411542
/// Hack: workaround for <https://github.com/PyO3/pyo3/issues/759>.
@@ -1559,7 +1560,9 @@ mod wit_world {
15591560
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15601561
let Self { value } = self;
15611562

1562-
f.debug_struct("Ok").field("value", value).finish()
1563+
f.debug_struct("Ok")
1564+
.field("value", &DebugLikeDisplay(value))
1565+
.finish()
15631566
}
15641567
}
15651568

@@ -1574,7 +1577,9 @@ mod wit_world {
15741577
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15751578
let Self { value } = self;
15761579

1577-
f.debug_struct("Err").field("value", value).finish()
1580+
f.debug_struct("Err")
1581+
.field("value", &DebugLikeDisplay(value))
1582+
.finish()
15781583
}
15791584
}
15801585

0 commit comments

Comments
 (0)