From 16de6a7f6876cf3fbc2f637f98272485eb0de9d5 Mon Sep 17 00:00:00 2001 From: johannesd3 Date: Fri, 2 Apr 2021 16:15:37 +0200 Subject: [PATCH] Improve api of discovery crate's builder --- discovery/examples/discovery.rs | 2 +- discovery/src/lib.rs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/discovery/examples/discovery.rs b/discovery/examples/discovery.rs index 267cee4f..cd913fd2 100644 --- a/discovery/examples/discovery.rs +++ b/discovery/examples/discovery.rs @@ -10,7 +10,7 @@ async fn main() { .init() .unwrap(); - let name = "Librespot".to_string(); + let name = "Librespot"; let device_id = hex::encode(Sha1::digest(name.as_bytes())); let mut server = librespot_discovery::Discovery::builder(device_id) diff --git a/discovery/src/lib.rs b/discovery/src/lib.rs index 3625d504..b1249a0d 100644 --- a/discovery/src/lib.rs +++ b/discovery/src/lib.rs @@ -11,6 +11,7 @@ mod server; +use std::borrow::Cow; use std::io; use std::pin::Pin; use std::task::{Context, Poll}; @@ -60,19 +61,19 @@ pub enum Error { impl Builder { /// Starts a new builder using the provided device id. - pub fn new(device_id: String) -> Self { + pub fn new(device_id: impl Into) -> Self { Self { server_config: server::Config { name: "Librespot".into(), device_type: DeviceType::default(), - device_id, + device_id: device_id.into(), }, port: 0, } } /// Sets the name to be displayed. Default is `"Librespot"`. - pub fn name(mut self, name: String) -> Self { + pub fn name(mut self, name: impl Into>) -> Self { self.server_config.name = name.into(); self } @@ -130,12 +131,12 @@ impl Builder { impl Discovery { /// Starts a [`Builder`] with the provided device id. - pub fn builder(device_id: String) -> Builder { + pub fn builder(device_id: impl Into) -> Builder { Builder::new(device_id) } /// Create a new instance with the specified device id and default paramaters. - pub fn new(device_id: String) -> Result { + pub fn new(device_id: impl Into) -> Result { Self::builder(device_id).launch() } }