File: derive-debug-transparent.rs

package info (click to toggle)
rust-derivative 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 724 kB
  • sloc: makefile: 2
file content (39 lines) | stat: -rw-r--r-- 774 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#[cfg(feature = "use_core")]
extern crate core;

#[macro_use]
extern crate derivative;

#[derive(Derivative)]
#[derivative(Debug="transparent")]
struct A(isize);

#[derive(Derivative)]
#[derivative(Debug="transparent")]
struct B([isize; 1]);

#[derive(Derivative)]
#[derivative(Debug)]
enum C {
    Foo(u8),
    #[derivative(Debug="transparent")]
    Bar(u8),
}

trait ToDebug {
    fn to_show(&self) -> String;
}

impl<T: std::fmt::Debug> ToDebug for T {
    fn to_show(&self) -> String {
        format!("{:?}", self)
    }
}

#[test]
fn main() {
    assert_eq!(A(42).to_show(), "42".to_string());
    assert_eq!(B([42]).to_show(), "[42]".to_string());
    assert_eq!(C::Foo(42).to_show(), "Foo(42)".to_string());
    assert_eq!(C::Bar(42).to_show(), "42".to_string());
}