-
I tried defining structs for a music database where tracks reference the album they belong to, and I get a cryptic build error. use turbosql::Turbosql;
#[derive(Turbosql, Default)]
struct Album {
rowid: Option<i64>,
title: Option<String>,
date: Option<String>,
artist: Option<String>,
}
#[derive(Turbosql, Default)]
struct Track {
rowid: Option<i64>,
album: Option<Album>,
disc_number: Option<i32>,
track_number: Option<i32>,
track_title: Option<String>,
}
fn main() {
let track = Track {
album: Some(Album{
title: Some("CVI".to_string()),
date: Some("2012-05-22".to_string()),
artist: Some("Royal Thunder".to_string()),
..Default::default()
}),
disc_number: Some(1),
track_number: Some(2),
track_title: Some("Whispering World".to_string()),
..Default::default()
}.insert();
} $ cargo build
Compiling turbosql-example v0.1.0 (/path/to/turbosql-example)
error[E0433]: failed to resolve: use of undeclared crate or module `serde_json`
--> src/main.rs:14:12
|
14 | album: Option<Album>,
| ^^^^^^ use of undeclared crate or module `serde_json`
For more information about this error, try `rustc --explain E0433`.
error: could not compile `turbosql-example` due to previous error If I add $ cargo build
Compiling turbosql-example v0.1.0 (/path/to/turbosql-example)
error[E0277]: the trait bound `Album: Serialize` is not satisfied
--> src/main.rs:14:5
|
14 | album: Option<Album>,
| ^^^^^^^------
| | |
| | required by a bound introduced by this call
| the trait `Serialize` is not implemented for `Album`
|
= note: required because of the requirements on the impl of `Serialize` for `Option<Album>`
note: required by a bound in `serde_json::to_string`
--> /home/aidan/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/serde_json-1.0.87/src/ser.rs:2141:17
|
2141 | T: ?Sized + Serialize,
| ^^^^^^^^^ required by this bound in `serde_json::to_string`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `turbosql-example` due to previous error |
Beta Was this translation helpful? Give feedback.
Answered by
trevyn
Oct 22, 2022
Replies: 1 comment
-
Doing There isn’t great support for automating foreign keys etc. yet, so if you want those to be two separate cross-referenced tables, you’ll need to treat them as separate flat tables and add rowid references manually. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
aidalgol
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doing
#[derive(serde::Serialize)]
onAlbum
could get you closer, but that still might not be exactly what you want.There isn’t great support for automating foreign keys etc. yet, so if you want those to be two separate cross-referenced tables, you’ll need to treat them as separate flat tables and add rowid references manually.