Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jojojet/to_debug
An alternative to the ToString trait that uses the Debug trait
https://github.com/jojojet/to_debug
Last synced: 7 days ago
JSON representation
An alternative to the ToString trait that uses the Debug trait
- Host: GitHub
- URL: https://github.com/jojojet/to_debug
- Owner: JoJoJet
- Created: 2021-08-26T16:31:04.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-26T16:52:02.000Z (over 3 years ago)
- Last Synced: 2024-12-08T21:43:48.208Z (about 1 month ago)
- Language: Rust
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# to_debug
This crate exports the [`ToDebug`] trait, which is an alternative to
[`ToString`] that uses [`Debug`] instead of [`Display`].This can be useful for writing doctests, as it allows you to inspect
the values of private fields:```rust
mod private {
#[derive(Debug)]
pub struct Person { name: String, age: u16 }
// constructor boilerplate...
}
let p = private::Person::new("Joseph", 20);
// assert_eq!(p.name, "Joseph"); // This would fail since `name` is private.
assert_eq!(p.to_debug(), r#"Person { name: "Joseph", age: 20 }"#);
```[`Debug`]: core::fmt::Debug
[`Display`]: core::fmt::DisplayLicense: MIT