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

async: User async-function-in-trait #77

Conversation

chrysn
Copy link
Contributor

@chrysn chrysn commented Nov 18, 2022

This is a WIP attempt to use the recent async-function-in-trait feature. It makes embedded-nal-async regress into nightly-only, but then again the feature(generic_associated_types) was not even removed yet, and it's barely possible to actually implement the traits described here without using impl Trait in the associated types' definitions anyway.

Benefits

  • Clearer interfaces
  • Better ergonomics for trait implementers
  • The provided version of connect() (that falls back to connect_from an unspecified address) is now actually provided

Downsides

  • The lifetimes of the associated types of the stack (Connected etc) had to go away due to known issues. But I kind of doubt we'd really have needed them.
    This probably needs further discussion, but before that I'll have to understand again myself why I had them there in the first place.
  • async-function-in-trait is an unstable feature (but it sounds like it would move toward stabilization fast, and it's my impression that it might be there even faster than impl Trait for associated types)

Status

This is experimentation at the moment, and only done for UDP (thus based on #73 until that is merged; only consider the top few commits for this PR). There is a branch on std-embedded-nal that already followed the switch. [edit: And because GitHub and GitLab don't federate PR mentions like modern issue trackers do: it's on https://gitlab.com/chrysn/std-embedded-nal/-/tree/async-fn-in-trait]

Porting DNS and TCP is a step on this PR's path from being a draft PR to a regular one.

chrysn added 11 commits October 1, 2022 20:20
One trait's receive_into still used the old receive name.
Elided lifetimes would have asked too little of the data / buffer
references.
This removes the lifetimes from the Connect associated types; leaving
them would cause errors (possibly related to [12681]), but I think that
stacks whose sockets are not 'static can work around this by
implementing the stack traits on a &'short stack instead.

[12681]: rust-lang/rust#102681
The connect method can now be provided properly.
@chrysn
Copy link
Contributor Author

chrysn commented Dec 2, 2022

Closing this because it's all being included in #73.

The "it's nightly again" and "TCP/DNS is missing" are moot since #78.

I've looked at the Connected (etc) lifetimes, and think that the old lifetimes were just a needless artifact -- so I see no open discussion points worth carrying over to #73.

@chrysn chrysn closed this Dec 2, 2022
@chrysn chrysn deleted the async-fn-in-trait branch December 2, 2022 22:45
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