linksplatform / linksplatform/Data.Doublets
Implement fast async API with asynchronous traits
- Dominant language
- C#
- Stars
- 14
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
### Implement async `Doublets` trait without dyn `Future` trait
`Pin>` from [async_trait](https://github.com/dtolnay/async-trait) eats a lot of time, but it can be fixed
## How to be
As you know, traits do not support non-dyn return `-> impl Trait`, but we can write:
```rs
trait ReturnImplTrait {
type Impl;
fn foo(&self) -> Self::Impl;
}
```
We also write [via [#![feature(type_alias_impl_trait)]](https://github.com/rust-lang/rfcs/blob/master/text/2515-type_alias_impl_trait.md) feature]:
```rs
impl ReturnImplTrait for () {
type Impl = impl Display;
fn foo(&self) -> Self::Impl {
"it's really working"
}
}
```
## But
It's a wrong code:
```rs
trait ReturnImplTrait {
type Impl;
fn foo(t: T) -> Self::Impl;
}
impl ReturnImplTrait for () {
type Impl = impl Display;
fn foo(t: T) -> Self::Impl {
t
}
}
```
Also, not work
```rs
trait ReturnImplTrait {
type Impl: Display;
fn foo(t: T) -> Self::Impl;
}
impl ReturnImplTrait for () {
type Impl = impl Display;
fn foo(t: T) -> Self::Impl {
t
}
}
```
### Hm… Use more features and magic!
Forward all generic params to `trait-type` (use [#![feature(generic_associated_types)]](https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md) feature)
**Oh, Miracle**
```rs
trait ReturnImplTrait {
type Impl;
fn foo(t: T) -> Self::Impl;
}
impl ReturnImplTrait for () {
type Impl = impl Display;
fn foo(t: T) -> Self::Impl {
t
}
}
```
Ok, use __`Future`__
```rs
trait AsyncSum {
type SumFuture, U>: Future>::Output>;
fn sum, U>(t: T, u: U) -> Self::SumFuture;
}
impl AsyncSum for () {
type SumFuture, U> = impl Future>::Output>;
fn sum, U>(t: T, u: U) -> Self::SumFuture {
async { t.add(u) }
}
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the Doublets trait and its current async_trait usage; the issue provides no file or test entry point. Compare the proposed generic associated Future design with the existing API, and consider the work complete when the async Doublets API no longer relies on dyn Future while retaining its required behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100