Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kurtbuilds/implicit-trait
https://github.com/kurtbuilds/implicit-trait
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/kurtbuilds/implicit-trait
- Owner: kurtbuilds
- Created: 2023-01-28T03:50:27.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-28T15:25:15.000Z (almost 2 years ago)
- Last Synced: 2024-10-06T09:37:07.708Z (about 1 month ago)
- Language: Rust
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `implicit-trait`
Create implicit traits to add methods to existing types.
```rust
use implicit_trait::implicit_trait;// Assume Foo is from another crate, so we can't implement methods on it.
pub struct Foo {
pub bar: i32,
pub baz: String,
}// Define new methods on Foo
#[implicit_trait]
impl FooExt for Foo {
fn bar(&self) -> i32 {
self.bar
}fn baz(&self) -> &str {
&self.baz
}
}// Use the new methods
fn main() {
let foo = Foo {
bar: 42,
baz: "hello".to_string(),
};
assert_eq!(foo.bar(), 42);
assert_eq!(foo.baz(), "hello");
}
```