https://github.com/robjtede/impl-more
Concise trait implementations
https://github.com/robjtede/impl-more
Last synced: 2 months ago
JSON representation
Concise trait implementations
- Host: GitHub
- URL: https://github.com/robjtede/impl-more
- Owner: robjtede
- License: apache-2.0
- Created: 2022-09-25T21:15:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-24T08:33:41.000Z (5 months ago)
- Last Synced: 2025-03-15T13:37:51.978Z (3 months ago)
- Language: Rust
- Size: 101 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# `impl-more`
> Concise trait implementations.
[](https://crates.io/crates/impl-more)
[](https://docs.rs/impl-more/0.1.9)

[](https://deps.rs/crate/impl-more/0.1.9)
[](https://crates.io/crates/impl-more)
[](https://circleci.com/gh/robjtede/impl-more/tree/main)# Usage
```rust
struct MyNewTypeStruct(String);impl_more::impl_as_ref!(MyNewTypeStruct => String);
impl_more::impl_as_mut!(MyNewTypeStruct => String);impl_more::impl_deref!(MyNewTypeStruct => String);
impl_more::impl_deref_mut!(MyNewTypeStruct);
// or, to deref through String too:
// impl_more::forward_deref_and_mut!(MyNewTypeStruct, ref str);impl_more::impl_from!(String => MyNewTypeStruct);
impl_more::impl_into!(MyNewTypeStruct => String);enum MyEnum {
Bar,
Qux,
}impl_more::impl_display_enum!(MyEnum, Bar => "bar", Qux => "qux");
enum Coords {
Xy(i64, i64),
Xyz(i64, i64, i64),
}impl_more::impl_display_enum!(
Coords,
Xy(x, y) => "{x}, {y}",
Xyz(x, y, z) => "{x}, {y}, {z}",
);#[derive(Debug)]
struct MyError(eyre::Report);impl_more::forward_display!(MyError);
impl_more::forward_error!(MyError);let err = MyError(eyre::eyre!("something went wrong"));
assert_eq!(err.source().unwrap().to_string(), "something went wrong");#[derive(Debug)]
enum Err {
Io(std::io::Error),
Generic(String),
}impl_more::impl_display_enum!(Err, Io(err) => "{err}", Generic(msg) => "{msg}");
impl_more::impl_error_enum!(Err, Io(err) => err);
```