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

AsRef restricted impls #285

Closed
MegaBluejay opened this issue Aug 8, 2023 · 0 comments · Fixed by #298
Closed

AsRef restricted impls #285

MegaBluejay opened this issue Aug 8, 2023 · 0 comments · Fixed by #298
Assignees

Comments

@MegaBluejay
Copy link
Contributor

MegaBluejay commented Aug 8, 2023

Currently there are 2 options for AsRef derives:

  • the default behaviour, where only implementations for field types are generated
  • [as_ref(forward)], which generates a generic impl for all types the field can be converted to

It would be useful to be able to list types for implementation explicitly, like with From

For example

#[derive(AsRef)]
struct Test {
    #[as_ref(str)]
    str_field: String,
    #[as_ref([u8])]
    u8_field: Vec<u8>,
}

This wouldn't work with [as_ref(forward)], since we'd have conflicting implementations for AsRef<[u8]>.

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 pushed a commit that referenced this issue Sep 15, 2023
Resolves #285 

## Synopsis

The `AsRef`/`AsMut` derives were less powerful than `From` and `Into`,
because there's no way to specify types into which forwarded
implementations should convert.

## Solution

Keep using the `forward` attribute argument for blanket forwarded impls,
and use a list of types for selective ones.

Co-authored-by: tyranron <tyranron@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants