Help me pass a string into Askama template with markdown enabled. PLEASE!

This Github issue sums up my same issue: askama with markdown filter using String: cannot move out of `self.name` which is behind a shared reference · Issue #719 · djc/askama · GitHub

I make an sql query to my database and retrieve some text that I have saved in markdown format. Then I attempt to pass in the value into an Askama template, but Askama's markdown feature doesn't take it.

async fn my_posts(State(pool): State<PgPool>,) -> impl IntoResponse {
    #[derive(FromRow)]
    struct Post {
        title: String,
        post_body: String,
    }

    let my_post = sqlx::query_as::<_, Post>("select title, post_body from my_posts")
        .fetch_all(&pool)
        .await
        .unwrap();

    // #[derive(Template)]
    // #[template(path = "post.html"]
    // pub struct MyTemplate {
    //     pub post_title: String,
    //     pub post_body: String,
    // }
    let template = MyTemplate {post_title: my_post[0].title, post_body: my_post[0].post_body};

    HtmlTemplate(template)
}

So the github issue states that markdown wants AsRef<str> or &'a str??? I've tried everything to convert the String into those two values but I just can't do it. I'm still at beginner level rust.

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.