我将从这个示例开始学习如何将 Axum 与 SQLx 结合使用。基本示例有效,但我在尝试继续前进时遇到问题。我正在使用一个简单的数据库表,如下所示:
todo | description
--------+--------------
todo_1 | doing todo 1
todo_2 | doing todo 2
todo_3 | doing todo 3
Run Code Online (Sandbox Code Playgroud)
我试图简单地返回“SELECT * FROM todos”,但出现错误。我认为我返回的类型是Result错误的,但我不知道下一步该怎么做。全文main.rs如下所示。
//! Example of application using <https://github.com/launchbadge/sqlx>
//!
//! Run with
//!
//! ```not_rust
//! cd examples && cargo run -p example-sqlx-postgres
//! ```
//!
//! Test with curl:
//!
//! ```not_rust
//! curl 127.0.0.1:3000
//! curl -X POST 127.0.0.1:3000
//! ```
use axum::{
async_trait,
extract::{Extension, FromRequest, …Run Code Online (Sandbox Code Playgroud) 我正在尝试完成一些相当简单的事情,但不知道如何在 Rust 中做到这一点。
我有一个 Vec<&Vec>,类似于下面的示例。
[
["a1", "b2", "c3"],
["d1", "e2", "f3"],
["g1", "h2", "i3"]
]
Run Code Online (Sandbox Code Playgroud)
我想在每个向量的末尾添加一个额外的字符串。
[
["a1", "b2", "c3", "something"],
["d1", "e2", "f3", "something"],
["g1", "h2", "i3", "something"]
]
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的如下:
vec_of_strings
.iter_mut()
.map(|x| x.clone().push("something".to_string()))
.collect::<Vec<_>>();
println!("{:?}", vec_of_strings);
Run Code Online (Sandbox Code Playgroud)
但输出显示没有附加任何内容。