Mange / mpris-rs

Idiomatic MPRIS D-Bus interface library for Rust
Apache License 2.0
67 stars 17 forks source link

allow to compare Metadata without copying everything #72

Closed mokurin000 closed 11 months ago

mokurin000 commented 11 months ago

so I could revert workarounds in https://github.com/waylyrics/waylyrics/commit/9cef9638c0ce6da63282862e86e9da14cf283ee8

Mange commented 11 months ago

I'm not sure if this would ever be useful, though. The metadata table can contain a lot of things you really can't compare well semantically; it's not just plain artist names and such in there.

I might suggest you implement PartialEq yourself on your struct in waylyrics and ignore the metadata, or that you separate the metadata from the fields you actually want to compare.

#[derive(PartialEq, Eq)]
struct TrackMetaComparison<'a> {
  title: &'a str,
  artists: &'a [str]>,
}

impl<'a> From<&'a TrackMeta> for TrackMetaComparison<'a> {
  fn from(meta: &'a TrackMeta) -> Self {
    Self {  /* ... */ }
  }
}

// Implement partial eq by converting both sides into a comparison struct and comparing that.
if track_meta == template {
  // ...
}

Perhaps I misunderstand what you did in waylyrics and I'm all ears if you want to elaborate a bit.

mokurin000 commented 11 months ago

I'm not sure if this would ever be useful, though. The metadata table can contain a lot of things you really can't compare well semantically; it's not just plain artist names and such in there.

I might suggest you implement PartialEq yourself on your struct in waylyrics and ignore the metadata, or that you separate the metadata from the fields you actually want to compare.

#[derive(PartialEq, Eq)]
struct TrackMetaComparison<'a> {
  title: &'a str,
  artists: &'a [str]>,
}

impl<'a> From<&'a TrackMeta> for TrackMetaComparison<'a> {
  fn from(meta: &'a TrackMeta) -> Self {
    Self {  /* ... */ }
  }
}

// Implement partial eq by converting both sides into a comparison struct and comparing that.
if track_meta == template {
  // ...
}

Perhaps I misunderstand what you did in waylyrics and I'm all ears if you want to elaborate a bit.

oh...thanks. I forgot there are lots items in Metadata