-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XML Improvements #130
base: main
Are you sure you want to change the base?
XML Improvements #130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
large lgtm, couple thoughts
let document: rekordcrate::xml::Document = | ||
quick_xml::de::from_reader(reader).expect("failed to deserialize XML"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you figured out how to avoid the expect
here yet? (the thing I criticized in the previous PR).
impl Serialize for Collection { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
#[derive(Serialize)] | ||
struct Value<'a> { | ||
/// Number of TRACK in COLLECTION | ||
#[serde(rename = "@Count")] | ||
entries: usize, | ||
/// Tracks | ||
#[serde(rename = "TRACK")] | ||
tracks: &'a Vec<Track>, | ||
} | ||
|
||
let value = Value { | ||
entries: self.tracks.len(), | ||
tracks: &self.tracks, | ||
}; | ||
|
||
value.serialize(serializer) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this could be simplified by using #[serde(getter = "tracks.len()")]
instead?
#[serde(rename = "@Count")] | ||
entries: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message doesn't explain why this is now @Count
when it was previously @Entries
. Can you elaborate?
Self::Turquoise => write!(f, "Turquoise"), | ||
Self::Blue => write!(f, "Blue"), | ||
Self::Violet => write!(f, "Violet"), | ||
Self::Custom(rgb) => write!(f, "#{:02X}{:02X}{:02X}", rgb.r, rgb.g, rgb.b), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative: delegate to the inner type if you don't need a stable representation
https://docs.rs/rgb/latest/rgb/type.RGB8.html#impl-Display-for-Rgb%3CT%3E
Self::Custom(rgb) => write!(f, "#{:02X}{:02X}{:02X}", rgb.r, rgb.g, rgb.b), | |
Self::Custom(rgb) => write!(f, "{}", rgb), |
pub enum StarRating { | ||
/// Zero Stars | ||
Zero = 0x00, | ||
/// One Star | ||
One = 0x33, | ||
/// Two Stars | ||
Two = 0x66, | ||
/// Three Stars | ||
Three = 0x99, | ||
/// Four Stars | ||
Four = 0xCC, | ||
/// Five Stars | ||
Five = 0xFF, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is a u8
under the hood, do fractional stars also exist (eg 230
corresponding to roughly 4.5
stars)? Do those need to be modeled here?
No description provided.