Skip to content

Commit

Permalink
refactor: improve uuid ergonomics
Browse files Browse the repository at this point in the history
  • Loading branch information
roderickvd committed Dec 1, 2024
1 parent 07128a5 commit c00aece
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/protocol/connect/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ impl Default for DeviceId {
/// assert!(matches!(device, DeviceId::Uuid(_)));
/// ```
fn default() -> Self {
Self::Uuid(*crate::Uuid::fast_v4())
Self::Uuid(crate::Uuid::fast_v4().into())
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ impl Client {
async fn disconnect(&mut self) -> Result<()> {
if let Some(controller) = self.controller() {
let close = Body::Close {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
};

let command = self.command(controller.clone(), close);
Expand Down Expand Up @@ -995,7 +995,7 @@ impl Client {
if let ConnectionState::Connected { controller, .. } = &self.connection_state {
// Evict the active connection.
let close = Body::Close {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
};

let command = self.command(controller.clone(), close);
Expand Down Expand Up @@ -1165,7 +1165,7 @@ impl Client {
async fn send_ping(&mut self) -> Result<()> {
if let Some(controller) = self.controller() {
let ping = Body::Ping {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
};

let command = self.command(controller.clone(), ping);
Expand Down Expand Up @@ -1214,7 +1214,7 @@ impl Client {
.collect();

// Generate a new list ID for the UI to pick up.
list.id = (*crate::Uuid::fast_v4()).into();
list.id = crate::Uuid::fast_v4().to_string();

debug!(
"extending queue {} with {} tracks",
Expand All @@ -1231,7 +1231,7 @@ impl Client {

// Then signal the controller to refresh its UI.
let contents = Body::RefreshQueue {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
};

let channel = self.channel(Ident::RemoteQueue);
Expand Down Expand Up @@ -1261,7 +1261,7 @@ impl Client {
/// * Progress report fails
async fn handle_refresh_queue(&mut self) -> Result<()> {
if let Some(queue) = self.queue.as_mut() {
queue.id = (*crate::Uuid::fast_v4()).into();
queue.id = crate::Uuid::fast_v4().to_string();
self.publish_queue().await?;
self.report_playback_progress().await
} else {
Expand All @@ -1287,7 +1287,7 @@ impl Client {
if let Some(controller) = self.controller() {
if let Some(queue) = self.queue.as_ref() {
let contents = Body::PublishQueue {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
queue: queue.clone(),
};

Expand Down Expand Up @@ -1320,7 +1320,7 @@ impl Client {
async fn send_acknowledgement(&mut self, acknowledgement_id: &str) -> Result<()> {
if let Some(controller) = self.controller() {
let acknowledgement = Body::Acknowledgement {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
acknowledgement_id: acknowledgement_id.to_string(),
};

Expand Down Expand Up @@ -1501,7 +1501,7 @@ impl Client {
async fn send_status(&mut self, command_id: &str, status: Status) -> Result<()> {
if let Some(controller) = self.controller() {
let status = Body::Status {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
command_id: command_id.to_string(),
status,
};
Expand Down Expand Up @@ -1552,7 +1552,7 @@ impl Client {
};

let progress = Body::PlaybackProgress {
message_id: (*crate::Uuid::fast_v4()).into(),
message_id: crate::Uuid::fast_v4().to_string(),
track: item,
quality: track.quality(),
duration: track.duration(),
Expand Down
6 changes: 6 additions & 0 deletions src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ impl FromStr for Uuid {
uuid::Uuid::from_str(s).map(Self).map_err(Into::into)
}
}

impl From<Uuid> for uuid::Uuid {
fn from(value: Uuid) -> Self {
*value
}
}

0 comments on commit c00aece

Please sign in to comment.