An attribute macro for easily writing extension trait pattern.
toml
[dependencies]
easy-ext = "0.2"
Compiler support: requires rustc 1.31+
```rust use easy_ext::ext;
pub impl
Code like this will be generated:
```rust
pub trait ResultExt
impl
You can elide the trait name.
```rust use easy_ext::ext;
impl
Note that in this case, #[ext]
assigns a random name, so you cannot
import/export the generated trait.
There are two ways to specify visibility.
The first way is to specify visibility at the impl level. For example:
```rust use easy_ext::ext;
// unnamed
pub impl str { fn foo(&self) {} }
// named
pub impl str { fn bar(&self) {} } ```
Another way is to specify visibility at the associated item level.
For example, if the method is pub
then the trait will also be pub
:
```rust use easy_ext::ext;
pub trait ResultExt
impl
This is useful when migrate from an inherent impl to an extension trait.
Note that the visibility of all the associated items in the impl
must be identical.
Note that you cannot specify impl-level visibility and associated-item-level visibility at the same time.
If you want the extension trait to be a subtrait of another trait,
add Self: SubTrait
bound to the where
clause.
```rust use easy_ext::ext;
impl
```rust use easy_ext::ext;
impl
```rust use easy_ext::ext;
impl
```rust use easy_ext::ext;
impl str { type Owned = String;
fn method(&self) -> Self::Owned {
self.to_owned()
}
} ```
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
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.