https://github.com/tamschi/fn-formats
Format trait wrappers for Fn(&mut Formatter) -> fmt::Result
https://github.com/tamschi/fn-formats
closures format-traits
Last synced: 3 months ago
JSON representation
Format trait wrappers for Fn(&mut Formatter) -> fmt::Result
- Host: GitHub
- URL: https://github.com/tamschi/fn-formats
- Owner: Tamschi
- License: other
- Created: 2020-08-30T12:01:30.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-05T17:00:59.000Z (over 2 years ago)
- Last Synced: 2025-01-28T05:23:21.573Z (5 months ago)
- Topics: closures, format-traits
- Language: Rust
- Homepage: https://lib.rs/crates/fn-formats
- Size: 72.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# fn-formats
[](https://lib.rs/crates/fn-formats)
[](https://crates.io/crates/fn-formats)
[](https://docs.rs/crates/fn-formats)
[](https://github.com/Tamschi/fn-formats/actions?query=workflow%3ACI+branch%3Adevelop)
[](https://github.com/Tamschi/fn-formats)
[](https://github.com/Tamschi/fn-formats/issues)
[](https://github.com/Tamschi/fn-formats/pulls)
[](https://web.crev.dev/rust-reviews/crate/fn-formats/)This is a small shim library for passing closures where you need one of the format traits (including [`Binary`] etc.).
[`Binary`]: https://doc.rust-lang.org/stable/core/fmt/trait.Binary.html
## Installation
Please use [cargo-edit](https://crates.io/crates/cargo-edit) to always add the latest version of this library:
```cmd
cargo add fn-formats
```## Example
```rust
use fn_formats::DebugFmt;let debug = DebugFmt(|f| {
f.debug_struct("StructName")
.field("list", &DebugFmt(|f| f.debug_list().entries(&[1, 2, 3]).finish()))
.field("set", &DebugFmt(|f| f.debug_set().entries(&[4, 5, 6]).finish()))
.finish()
});assert_eq!(format!("{:?}", debug), "StructName { list: [1, 2, 3], set: {4, 5, 6} }");
```## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or )
* MIT license
([LICENSE-MIT](LICENSE-MIT) or )at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.## [Code of Conduct](CODE_OF_CONDUCT.md)
## [Changelog](CHANGELOG.md)
## Versioning
`fn-formats` strictly follows [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html) with the following exceptions:
* The minor version will not reset to 0 on major version changes (except for v1).
Consider it the global feature level.
* The patch version will not reset to 0 on major or minor version changes (except for v0.1 and v1).
Consider it the global patch level.This includes the Rust version requirement specified above.
Earlier Rust versions may be compatible, but this can change with minor or patch releases.Which versions are affected by features and patches can be determined from the respective headings in [CHANGELOG.md](CHANGELOG.md).