Skip to content

Comments

Support unnamed extension trait#9

Merged
bors[bot] merged 1 commit intomasterfrom
unnamed
Mar 4, 2020
Merged

Support unnamed extension trait#9
bors[bot] merged 1 commit intomasterfrom
unnamed

Conversation

@taiki-e
Copy link
Owner

@taiki-e taiki-e commented Mar 4, 2020

This allows to elide the trait name. Note that in this case, #[ext] assigns a random name, so you cannot import/export the generated trait.

use easy_ext::ext;
#[ext]
impl<T, E> Result<T, E> {
    fn err_into<U>(self) -> Result<T, U>
    where
        E: Into<U>,
    {
        self.map_err(Into::into)
    }
}

@taiki-e taiki-e added the C-enhancement Category: A new feature or an improvement for an existing one label Mar 4, 2020
#[proc_macro_attribute]
pub fn ext(args: TokenStream, input: TokenStream) -> TokenStream {
let ext_ident = match syn::parse_macro_input!(args) {
None => format_ident!("__ExtTrait{}", hash(&input)),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See taiki-e/auto_enums#60 for reasons to use the hash value of the input AST.

@taiki-e
Copy link
Owner Author

taiki-e commented Mar 4, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 4, 2020

@bors bors bot merged commit 59d3c51 into master Mar 4, 2020
@bors bors bot deleted the unnamed branch March 4, 2020 19:09
@taiki-e taiki-e removed the C-enhancement Category: A new feature or an improvement for an existing one label Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant