Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unnamed extension trait #9

Merged
merged 1 commit into from
Mar 4, 2020
Merged

Support unnamed extension trait #9

merged 1 commit into from
Mar 4, 2020

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
@@ -121,8 +127,12 @@ macro_rules! error {
/// * The visibility of all the items in the original `impl` must be identical.
#[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