Fix deserialization with some attributes
The "repository" field doesn't have a type right now, so I'm going to skip deserializing it. The returned JSON has a value for this field, but Serde will ignore it. The `Packages.pkg_type` field is called "type" in the JSON string (and Go code, as mentioned in the comment). Similarly, the PackageType enum I have to represent this field in Rust has capital starting letters where the JSON uses all lowercase. Both problems are solved with a Serde rename attribute.
This commit is contained in:
@@ -14,8 +14,10 @@ pub struct Package {
|
||||
id: u64,
|
||||
name: String,
|
||||
owner: Author,
|
||||
#[serde(skip)]
|
||||
repository: (), // TODO: Create a `struct Repository`
|
||||
pkg_type: PackageType, // field is "type" in Go, but that's a keyword in Rust.
|
||||
#[serde(rename = "type")] // field is "type" in JSON & Go, but that's a
|
||||
pkg_type: PackageType, // keyword in Rust so we need to serde-rename it.
|
||||
version: String,
|
||||
}
|
||||
|
||||
@@ -37,6 +39,7 @@ impl Package {
|
||||
|
||||
/// A marker for the kind of package being handled.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PackageType {
|
||||
Alpine,
|
||||
Arch,
|
||||
|
||||
Reference in New Issue
Block a user