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

Allowing each and into on a vec #209

Closed
Freyskeyd opened this issue May 7, 2021 · 2 comments
Closed

Allowing each and into on a vec #209

Freyskeyd opened this issue May 7, 2021 · 2 comments

Comments

@Freyskeyd
Copy link

Freyskeyd commented May 7, 2021

Hello,

I'm trying to have a nice api for one of my crates and I was wondering if I could be able to have a struct like this:

#[derive(derive_builder::Builder, Debug, Clone)]
#[builder(setter(into))]
struct SessionManagementPacketResult {
    #[builder(default = "SessionState::Opening")]
    session_state: SessionState,
    #[builder(setter(each = "packet", into))]
    packets: Vec<Packet>,
}

I want to be able to do session.packet(xx).packet(xx) where xx implement From<xx> for Packet (the into part) but it seems to not work, or the into isn't applied to packet.

Any idea of a workaround on that?

Thank's!

@TedDriggs
Copy link
Collaborator

TedDriggs commented May 12, 2021

I believe the issue there is that Extend has its own type coercion magic going on and stacking the two breaks inference. See this discussion from the initial PR to add each.

If you can think of a way to do it, I'd probably make the API be:

#[builder(setter(each(name = "packet", into), into))]

That would avoid breaking backwards compatibility, and if there are some tradeoffs needed to make it work, this would make the author's choice explicit.

@TedDriggs
Copy link
Collaborator

This is fixed by #234

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 a pull request may close this issue.

2 participants