Amigo
July 22, 2021, 11:29am
1
fn cat(path: &Path) -> io::Result {
let mut f = File::open(path)?;
let mut s = String::new();
match f.read_to_string(&mut s) {
Ok(_) => Ok(s),
Err(e) => Err(e),
}
The above code is blocking right..pls turn that into async with Future trait implementation
alice
July 22, 2021, 11:32am
2
Please follow our syntax highlighting guidelines
To format code in this forum you need to surround the code with three backticks (```). For example, typing this...
```
fn main() {
println!()
}
```
...will be rendered as highlighted Rust code, like so:
fn main() {
println!()
}
You can also tell the forum software which language you're using by adding the language after the opening backticks.
```cpp
#include <iostream>
int main() {
std::cout << "Hello World!";
}
```
Will appear with highlighting as:
#include <iostream>
int main(…
alice
July 22, 2021, 11:34am
3
use std::io;
use std::path::Path;
use tokio::fs::File;
use tokio::io::AsyncReadExt;
async fn cat(path: &Path) -> io::Result<String> {
let mut f = File::open(path).await?;
let mut s = String::new();
match f.read_to_string(&mut s).await {
Ok(_) => Ok(s),
Err(e) => Err(e),
}
}
3 Likes
Amigo
July 22, 2021, 1:31pm
4
Thanks now am understand..
Last and final can u pls give the poll method implementation of the File.open() method of the above example .
Just for the idea..
The only poll method is enough..
Thanks
cliff
July 22, 2021, 6:22pm
5
the source of that method is available on github. A search for tokio should turn up the repo pretty quickly.
system
Closed
October 20, 2021, 6:22pm
6
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.