From 7c867695b5c89a5c11704bf8d9ebd6100421f2ac Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 11 Oct 2025 14:49:54 -0400 Subject: [PATCH] Cleanup --- src/song.rs | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/song.rs b/src/song.rs index bbe9f06..a389f2b 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,12 +1,12 @@ use std::io::{Read, Write}; +use rand::Rng; +use serde::{Deserialize, Serialize}; + use crate::constants; use crate::init; use crate::types; -use rand::Rng; -use serde::{Deserialize, Serialize}; - #[derive(Clone, Debug, Default, Deserialize, Serialize, utoipa::ToSchema)] pub struct Song { #[serde(skip_serializing_if = "init::is_uuid_nil")] @@ -170,29 +170,35 @@ impl Song { // TODO: Add function to remove file from the filesystem } -/// Copies a song using the source song's data -pub fn copy_song(song_source: &Song, song_target: &mut Song) -> Result<(), std::io::Error> { - match song_target.song_path() { - Ok(songpath) => { - let p = std::path::Path::new(&songpath); - if p.exists() { - Err(std::io::Error::other( - "Cannot copy song over to one that already exists", - )) - } else { - if song_target.data.is_empty() { - song_target.data = song_source.data.clone(); +/// I/O operations for songs +pub mod io { + /// Copies a song using the source song's data + pub fn copy_song( + song_source: &super::Song, + song_target: &mut super::Song, + ) -> Result<(), std::io::Error> { + match song_target.song_path() { + Ok(songpath) => { + let p = std::path::Path::new(&songpath); + if p.exists() { + Err(std::io::Error::other( + "Cannot copy song over to one that already exists", + )) } else { - song_target.data.clear(); - song_target.data = song_source.data.clone(); - } + if song_target.data.is_empty() { + song_target.data = song_source.data.clone(); + } else { + song_target.data.clear(); + song_target.data = song_source.data.clone(); + } - match song_target.save_to_filesystem() { - Ok(_) => Ok(()), - Err(err) => Err(err), + match song_target.save_to_filesystem() { + Ok(_) => Ok(()), + Err(err) => Err(err), + } } } + Err(err) => Err(err), } - Err(err) => Err(err), } }