Add documentation for TemplateProcessor and compare events in CmusQueryResponse

This commit is contained in:
Anas Elgarhy 2023-02-21 05:07:56 +02:00
parent e34d676eb9
commit a82dc31beb
No known key found for this signature in database
GPG Key ID: 0501802A1D496528
3 changed files with 10 additions and 0 deletions

View File

@ -15,6 +15,9 @@ use typed_builder::TypedBuilder;
pub trait TemplateProcessor {
fn process(&self, template: &String) -> String;
/// Returns a vector of keys found in the template.
/// The keys are the strings between curly braces.
fn get_keys(template: &String) -> Vec<String> {
let mut keys = Vec::new(); // Just a buffer to store the keys.
let mut key = String::new(); // Just a buffer to build the key.
@ -85,6 +88,9 @@ pub enum CmusError {
}
impl TemplateProcessor for Track {
/// Process the template with the track metadata.
/// The template is a string with placeholders that will be replaced with the track metadata.
/// The unknown placeholders will be skipped (don't replaced with anything, because they are maybe placeholders for player settings).
fn process(&self, template: &String) -> String {
#[cfg(feature = "debug")]
{

View File

@ -38,6 +38,9 @@ pub enum AAAMode {
}
impl TemplateProcessor for PlayerSettings {
/// Replace all keys in the template with the corresponding values.
/// If the key is unknown, it will be replaced with an empty string.
/// This function should be used after the track metadata placeholders have been replaced.
fn process(&self, template: &String) -> String {
#[cfg(feature = "debug")]
{

View File

@ -44,6 +44,7 @@ impl CmusQueryResponse {
PlayerSettings::from_str(&self.player_settings_row)
}
/// Compare this response with another one, and return the events that happened.
pub fn events(&self, other: &Self) -> Result<Vec<CmusEvent>, CmusError> {
#[cfg(feature = "debug")]
info!("Comparing cmus responses: {:?} and {:?}", self, other);