inline code documentation completed to satisfactory level

This commit is contained in:
djaidjai committed 2023-05-11 17:00:38 +02:00
1 parent bc1a1c00a4
commit c594cd8a6a
5 files changed
+121 -15

No files matched your search

+34
View File
@@ -1,7 +1,21 @@
//! This file deals with updating the actual message, including proper formatting.
use log::{debug, trace};
use mpris::{MetadataValue};
use crate::structs::{config::Config, data::Data};
/// This function converts a given MetadataValue to a String.
/// Note that two types of the MetadataValue enum are currently unsupported:
/// Both the Map and Unsupported types currently lead the program to panic!
/// The HashMap because I honestly don't know when a metadata value would be encoded as such (and am too lazy to dig through the crate's source code),
/// The Unsupported type should be self-explanatory.
///
/// Input:
/// v: MetadataValue to convert.
/// sep: seperation character to insert between entries of a Vec.
///
/// Output:
/// String representing the input MetadataValue.
fn value_to_string(v: &MetadataValue, sep: char) -> String {
match v {
MetadataValue::String(v) => v.to_string(),
@@ -28,6 +42,16 @@ fn value_to_string(v: &MetadataValue, sep: char) -> String {
}
}
/// This function converts one specific instance of MetadataValue to an appropriate String.
/// It deals with the xesam:userRating type. This is a float (0.0 <= v <= 1.0), but should be represented on a scale fron 0 to 10 (according to me).
/// As such, it converts the float value to a visually appealing 5-symbol string.
///
/// Input:
/// r: MetadataValue, should be of the enum type f64 (unchecked).
/// str: Vec containing precomputed rating strings to select from.
///
/// Output:
/// Some(String) if a rating exists, None otherwise.
fn rating_to_string(r: Option<&MetadataValue>, str: &Vec<String>) -> Option<String> {
match r {
Some(rating) => {
@@ -38,15 +62,25 @@ fn rating_to_string(r: Option<&MetadataValue>, str: &Vec<String>) -> Option<Stri
Some(str[i as usize].clone()) //TODO: still inefficient. would be better to note the idx and load it in print_text
} else {
debug!("failed to convert MetadataValue to f64!");
None
}
},
None => {
trace!("no userRating MetadataValue found!");
None
},
}
}
/// This higher level function updates the to be output Hashmap of strings.
/// It does so by querying each metadata field in config to the current player, then updating the Hashmap in Data with the new value(s).
/// "xesam:userRating" is treated separately, due to requiring a different output format.
///
/// Input:
/// cfg: Config struct for the program. Contains the wanted metadata fields.
/// data: mutable Data struct for the program. Its' Hashmap containing strings is updated.
/// ratings: Vec of precomputed rating strings.
pub fn update_message(cfg: &Config, data: &mut Data, ratings: &Vec<String>) {
if let Some(player) = &data.current_player {
if let Ok(meta) = player.get_metadata() {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.