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

derive(AsRef) should also derive identity impl. #123

Open
wdanilo opened this issue Apr 10, 2020 · 2 comments
Open

derive(AsRef) should also derive identity impl. #123

wdanilo opened this issue Apr 10, 2020 · 2 comments

Comments

@wdanilo
Copy link

wdanilo commented Apr 10, 2020

Hi! I believe that:

#[derive(AsRef)]
struct Foo { t:i32 }

should generate identity AsRef impl in addition to what it generates now:

impl AsRef<Foo> for Foo {
    fn as_ref(&self) -> &Self {
        self
    }
}

Making these instances by hand is cumbersome and they should be generated automatically.

tyranron added a commit that referenced this issue Aug 18, 2023
## Synopsis

This PR is a part of replacing all attributes having `syn::Meta` syntax
to custom parsing, similarly to #241, #248.

Paves the way for #285, and possibly other enhancements such as an
opt-in #123.


## Solution

Implement custom attribute parsing without `utils::State`.

Co-authored-by: Kai Ren <tyranron@gmail.com>
@JelteF
Copy link
Owner

JelteF commented Dec 22, 2023

I'm not entirely sure when you would actually want this, but if you can give some useful example I'm definitely open to accepting PRs for this. Should be behind a attribute flag though, e.g. as_ref(Self)

@tyranron
Copy link
Collaborator

@JelteF @wdanilo I think that this is quite a particular pattern, not enforced neither in std, nor being useful in a common case.

Now, having the ability to specify #[as_ref(Self)] should solve the @wdanilo's situation good enough, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants