Skip to content

Commit

Permalink
1. Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
denisandroid committed Mar 29, 2024
1 parent 4631031 commit fe76a7e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ homepage = "https://crates.io/crates/include_tt"
license = "MIT/Apache-2.0"
readme = "README.md"

description = "Macro for easily copying impl block code for different types."
keywords = ["copy_impl", "macros", "code-transformation", "clucompany"]
description = "Macro for effortlessly duplicating impl block code across various types in Rust."
keywords = ["copy_impl", "macro", "code-transformation", "clucompany"]
categories = ["development-tools", "development-tools::build-utils"]

[dependencies]
46 changes: 44 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,52 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.

#![doc = include_str!("../README.md")]

/*!
Macro for effortlessly duplicating impl block code across various types in Rust.
## Example:
```rust
use std::{error::Error, fmt::Write};
use copy_impl::copy_impl;
struct CustomNum<T>(T);
struct UncheckedCustomNum<T>(T);
copy_impl! {
impl (CustomNum<i8>),
impl (CustomNum<i16>),
impl (CustomNum<i32>),
impl (UncheckedCustomNum<i8>),
impl (UncheckedCustomNum<i16>) {
pub fn write_to(&self, mut w: impl Write) -> Result<(), std::fmt::Error> {
write!(w, "{}", self.0)
}
}
}
fn main() -> Result<(), Box<dyn Error>> {
let mut tbuff = String::new();
CustomNum(1i8).write_to(&mut tbuff)?;
CustomNum(2i16).write_to(&mut tbuff)?;
CustomNum(3i32).write_to(&mut tbuff)?;
UncheckedCustomNum(4i8).write_to(&mut tbuff)?;
UncheckedCustomNum(5i16).write_to(&mut tbuff)?;
// UncheckedCustomNum(6i32).write_to(&mut tbuff)?;
/*
no method named `write_to` found for struct `UncheckedCustomNum<i32>` in the current scope
the method was found for
- `UncheckedCustomNum<i8>`
- `UncheckedCustomNum<i16>`
*/
assert_eq!(tbuff, "12345");
Ok(())
}
```
*/

Expand Down

0 comments on commit fe76a7e

Please sign in to comment.