Background (outdated)
deep-dive
Leave questions, observations, discussion topics below.
trait ?async Iterator {
type Item;
?async fn next(&mut self) -> Option<Self::Item>;
fn size_hint(&self) -> (usize, Option<usize>) {..}
}
struct AsyncFile;
// always async impl!
impl async Iterator for AsyncFile { .. }
trait Foo {
async fn bar() {}
async fn baz() {}
async fn bin() {}
}
// ... and how do we mark all methods in `Foo` as `Send`
trait async Foo {
async fn bar() {}
}
// say we start with this
trait async HealthCheck { .. }
async fn foo(check: impl async HealthCheck) { .. }
// .. but later on we realize `HealthCheck` may also
// be useful in !async contexts, so we change it to this:
trait ?async HealthCheck { .. }
// .. usage remains exactly as it was before!:
async fn foo(check: impl async HealthCheck) { .. }
// .. but maybe we want `foo` to also become `?async`, so we then can
// opt into instead changing it to:
?async fn foo(check: impl ?async HealthCheck) { .. }
trait async HealthCheck { .. }
async fn foo(check: impl async(Send) HealthCheck) { .. }
Are methods Send
by default and we opt out? Or do we opt in to Send
?
// Do we write this?
async fn foo(check: impl async(Send) HealthCheck) { .. }
// Or this?
async fn foo(check: impl async(?Send) HealthCheck) { .. }
async
show up in imports?use my_crate::HealthCheck;
// Could you do...
use my_crate::async(Send) HealthCheck as async HealthCheck;
// What about aliases
type UsizeOption = Option<usize>;
trait AsyncHealthCheck = async HealthCheck;
fn foo(x: impl async(Send) AsyncHealthCheck) { .. }
If we can hide async
behind a trait alias, we shouldn't require it on the trait definition.
trait async HealthCheck {
async fn check(...);
}
trait async SendHealthCheck = async(Send) HealthCheck;
fn foo(check: impl async HealthCheck) { .. }
fn bar(check: impl async SendHealthCheck) { .. }
trait SendHealthCheck = async(Send) HealthCheck;
trait async HealthCheck {
async fn check(...);
}
trait async SendHealthCheck = async(Send) HealthCheck;
fn foo(check: impl HealthCheck + Send) { .. }
fn bar(check: impl SendHealthCheck) { .. }
// Trait today!
trait FixedLengthIterator: Iterator { .. }
// Maybe-async variant
trait ?async FixedLengthIterator: ?async Iterator { .. }
// Always async variant
trait async FixedLengthIterator: async Iterator { .. }
async Trait
and Trait
different names?Can I do this?
trait Bar {
fn foo();
}
trait async Bar {
async fn baz();
}
Yosh: probably not; they live in the same namespace. But you could imagine an async
and !async
impl of the same ?async
trait on a single type.
struct ?async File { .. }
// either..
impl ?async Read
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
![image alt](https:// "title") | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | Emoji list | ||
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing