Skip to content

Commit 16de6a7

Browse files
committed
Improve api of discovery crate's builder
1 parent a7f9e0a commit 16de6a7

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

discovery/examples/discovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async fn main() {
1010
.init()
1111
.unwrap();
1212

13-
let name = "Librespot".to_string();
13+
let name = "Librespot";
1414
let device_id = hex::encode(Sha1::digest(name.as_bytes()));
1515

1616
let mut server = librespot_discovery::Discovery::builder(device_id)

discovery/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
mod server;
1313

14+
use std::borrow::Cow;
1415
use std::io;
1516
use std::pin::Pin;
1617
use std::task::{Context, Poll};
@@ -60,19 +61,19 @@ pub enum Error {
6061

6162
impl Builder {
6263
/// Starts a new builder using the provided device id.
63-
pub fn new(device_id: String) -> Self {
64+
pub fn new(device_id: impl Into<String>) -> Self {
6465
Self {
6566
server_config: server::Config {
6667
name: "Librespot".into(),
6768
device_type: DeviceType::default(),
68-
device_id,
69+
device_id: device_id.into(),
6970
},
7071
port: 0,
7172
}
7273
}
7374

7475
/// Sets the name to be displayed. Default is `"Librespot"`.
75-
pub fn name(mut self, name: String) -> Self {
76+
pub fn name(mut self, name: impl Into<Cow<'static, str>>) -> Self {
7677
self.server_config.name = name.into();
7778
self
7879
}
@@ -130,12 +131,12 @@ impl Builder {
130131

131132
impl Discovery {
132133
/// Starts a [`Builder`] with the provided device id.
133-
pub fn builder(device_id: String) -> Builder {
134+
pub fn builder(device_id: impl Into<String>) -> Builder {
134135
Builder::new(device_id)
135136
}
136137

137138
/// Create a new instance with the specified device id and default paramaters.
138-
pub fn new(device_id: String) -> Result<Self, Error> {
139+
pub fn new(device_id: impl Into<String>) -> Result<Self, Error> {
139140
Self::builder(device_id).launch()
140141
}
141142
}

0 commit comments

Comments
 (0)