added serde dep; added questions.rs

This commit is contained in:
David Westgate 2024-04-24 13:05:09 -07:00
parent 88f4dd6bd6
commit c62357fd3e
3 changed files with 31 additions and 4 deletions

9
Cargo.lock generated
View File

@ -733,6 +733,7 @@ name = "rust-web"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"axum", "axum",
"serde",
"tokio", "tokio",
"warp", "warp",
] ]
@ -769,18 +770,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.197" version = "1.0.198"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.197" version = "1.0.198"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@ -7,5 +7,6 @@ edition = "2021"
[dependencies] [dependencies]
axum = "0.7.5" axum = "0.7.5"
serde = "1.0.198"
tokio = { version = "1.2", features = ["full"] } tokio = { version = "1.2", features = ["full"] }
warp = "0.3.7" warp = "0.3.7"

25
src/question.rs Normal file
View File

@ -0,0 +1,25 @@
struct Question {
id: QuestionId,
title: String,
content: String,
tags: Option<Vec<String>>,
}
struct QuestionId(String);
impl Question{
fn new(id: QuestionId, title: String, content: String, tags: Option<Vec<String>>) -> Self {
Question {
id,
title,
content,
tags,
}
}
}
impl IntoResponse for &Question {
fn into_response(self) -> Response {
(StatusCode::OK, Json(&self)).into_response()
}
}