-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support converting Value into Debug (#34)
- Loading branch information
Showing
18 changed files
with
745 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*! | ||
Integration between `sval` and `std::fmt`. | ||
# From `sval` to `std::fmt` | ||
A type that implements [`sval::Value`](../value/trait.Value.html) can be converted into | ||
a type that implements [`std::fmt::Debug`]: | ||
``` | ||
# struct MyValue; | ||
# impl sval::value::Value for MyValue { | ||
# fn stream(&self, stream: &mut sval::value::Stream) -> Result<(), sval::value::Error> { | ||
# unimplemented!() | ||
# } | ||
# } | ||
# let my_value = MyValue; | ||
let my_debug = sval::fmt::to_debug(my_value); | ||
``` | ||
*/ | ||
|
||
use crate::{ | ||
std::fmt::{ | ||
self, | ||
Debug, | ||
Formatter, | ||
}, | ||
Value, | ||
}; | ||
|
||
mod to_debug; | ||
|
||
/** | ||
Convert a [`Value`] into a [`Debug`]. | ||
The formatted value is not guaranteed to be exactly the same as | ||
a `Debug` implementation that might exist on the type. | ||
This method doesn't need to allocate or perform any buffering. | ||
*/ | ||
pub fn to_debug(value: impl Value) -> impl Debug { | ||
self::to_debug::ToDebug(value) | ||
} | ||
|
||
/** | ||
Format a [`Value`] using the given [`Formatter`]. | ||
*/ | ||
pub fn debug(value: impl Value, f: &mut Formatter) -> fmt::Result { | ||
to_debug(value).fmt(f) | ||
} |
Oops, something went wrong.