Skip to content

How to use csv-async crate with Rocket? #2601

Discussion options

You must be logged in to vote

I'm not familiar with csv-async, but from a glance, what is your intent when passing AsyncReader a Result<T, E>?

The problem you are encountering is that Result<T, E> doesn't impl AsyncRead. You cannot impl this either, as Result is defined in Rust core. Of course, you could use a NewType to get around it, but all of that can be sidestepped by just structuring your code differently.

#[get("/")]
async fn hello() -> Template {
    // handle for errors first
    let Ok(file) = tokio::fs::File::open("csv/entities.csv").await else {
        todo!("return 404 template or whatever")
    };

    // now we can use the file however we like
    let mut reader = csv_async::AsyncReader::from_reader(file)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@padraigconnolly
Comment options

@padraigconnolly
Comment options

Answer selected by padraigconnolly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants