Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c2fad59cac
|
|||
|
1d2dd5ebe9
|
|||
|
c2f2c210fe
|
|||
|
92fd492be4
|
|||
|
71544eed2f
|
|||
|
da52603d06
|
|||
|
56f1546292
|
|||
|
e7667b8f80
|
Generated
+1
-1
@@ -192,7 +192,7 @@ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.11.3"
|
version = "0.11.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"josekit",
|
"josekit",
|
||||||
"rand",
|
"rand",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.11.3"
|
version = "0.11.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
description = "models used for the icarus project"
|
description = "models used for the icarus project"
|
||||||
|
|||||||
+1
-36
@@ -37,42 +37,7 @@ pub mod collection {
|
|||||||
pub artist: String,
|
pub artist: String,
|
||||||
pub disc: i32,
|
pub disc: i32,
|
||||||
pub track: i32,
|
pub track: i32,
|
||||||
/// In seconds
|
// In seconds
|
||||||
pub duration: f64,
|
pub duration: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize_json(json_data: &str, album: &mut Album) -> Result<(), serde_json::Error> {
|
|
||||||
match serde_json::from_str::<Album>(json_data) {
|
|
||||||
Ok(parsed_album) => {
|
|
||||||
*album = parsed_album;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn test_deserilize_album_collection_json() {
|
|
||||||
let album_file_path = "tests/album.json";
|
|
||||||
let album_file_content = match std::fs::read_to_string(album_file_path) {
|
|
||||||
Ok(content) => content,
|
|
||||||
Err(err) => {
|
|
||||||
assert!(false, "Error: {err:?}");
|
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut album = super::collection::Album::default();
|
|
||||||
match super::collection::deserialize_json(&album_file_content, &mut album) {
|
|
||||||
Ok(_) => {
|
|
||||||
assert_eq!(3, album.tracks.len(), "Track count do not match");
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
assert!(false, "Error: {err:?}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user