Skip to content

Commit

Permalink
chore: replace ToString impl with Display
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-yantsen committed Mar 3, 2024
1 parent 19fd161 commit 1acdcb8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
14 changes: 8 additions & 6 deletions crates/plex-api/src/media_container/preferences/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod deserializer;

use std::fmt::Display;

use super::MediaContainer;
use serde::Deserialize;

Expand Down Expand Up @@ -36,13 +38,13 @@ pub enum Value {
Double(f64),
}

impl ToString for Value {
fn to_string(&self) -> String {
impl Display for Value {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Value::Text(s) => s.to_owned(),
Value::Int(i) => i.to_string(),
Value::Bool(b) => (if *b { "1" } else { "0" }).to_owned(),
Value::Double(d) => d.to_string(),
Value::Text(s) => write!(f, "{}", s),
Value::Int(i) => write!(f, "{}", i),
Value::Bool(b) => write!(f, "{}", if *b { "1" } else { "0" }),
Value::Double(d) => write!(f, "{}", d),
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/plex-api/src/myplex/claim_token.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use crate::{http_client::HttpClient, url::MYPLEX_CLAIM_TOKEN_PATH, Error, Result};
use http::StatusCode;
use isahc::AsyncReadResponseExt;
Expand Down Expand Up @@ -52,8 +54,8 @@ impl ClaimToken {
}
}

impl ToString for ClaimToken {
fn to_string(&self) -> String {
self.token.clone()
impl Display for ClaimToken {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.token)
}
}
8 changes: 4 additions & 4 deletions crates/plex-api/src/myplex/sharing/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{
Deserialize, Serialize,
};
use std::{
fmt::{Formatter, Result as FmtResult},
fmt::{Display, Formatter, Result as FmtResult},
result::Result as StdResult,
};

Expand Down Expand Up @@ -93,8 +93,8 @@ impl Serialize for SharingFilter {
}
}

impl ToString for SharingFilter {
fn to_string(&self) -> String {
impl Display for SharingFilter {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let mut ret: Vec<String> = vec![];

if !self.content_rating.is_empty() {
Expand All @@ -116,6 +116,6 @@ impl ToString for SharingFilter {
ret.push(format!("label!={}", self.exclude_label.join("%2C")))
}

ret.join("|")
write!(f, "{}", ret.join("|"))
}
}
48 changes: 28 additions & 20 deletions crates/plex-api/src/server/transcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ impl ProfileSetting {
}
}

impl ToString for ProfileSetting {
fn to_string(&self) -> String {
format!("{}({})", self.setting, self.params.join("&"))
impl Display for ProfileSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}({})", self.setting, self.params.join("&"))
}
}

Expand All @@ -173,16 +173,20 @@ pub enum VideoSetting {
FrameRate,
}

impl ToString for VideoSetting {
fn to_string(&self) -> String {
match self {
VideoSetting::Width => "video.width".to_string(),
VideoSetting::Height => "video.height".to_string(),
VideoSetting::BitDepth => "video.bitDepth".to_string(),
VideoSetting::Level => "video.level".to_string(),
VideoSetting::Profile => "video.profile".to_string(),
VideoSetting::FrameRate => "video.frameRate".to_string(),
}
impl Display for VideoSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
VideoSetting::Width => "video.width",
VideoSetting::Height => "video.height",
VideoSetting::BitDepth => "video.bitDepth",
VideoSetting::Level => "video.level",
VideoSetting::Profile => "video.profile",
VideoSetting::FrameRate => "video.frameRate",
}
)
}
}

Expand All @@ -196,13 +200,17 @@ pub enum AudioSetting {
BitDepth,
}

impl ToString for AudioSetting {
fn to_string(&self) -> String {
match self {
AudioSetting::Channels => "audio.channels".to_string(),
AudioSetting::SamplingRate => "audio.samplingRate".to_string(),
AudioSetting::BitDepth => "audio.bitDepth".to_string(),
}
impl Display for AudioSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
AudioSetting::Channels => "audio.channels",
AudioSetting::SamplingRate => "audio.samplingRate",
AudioSetting::BitDepth => "audio.bitDepth",
}
)
}
}

Expand Down

0 comments on commit 1acdcb8

Please sign in to comment.