pub struct FileHandler;Implementations§
Source§impl FileHandler
impl FileHandler
Sourcepub fn save<T: Serialize>(
data: &[T],
format: &FileFormat,
filename_prefix: &str,
) -> Result<String>
pub fn save<T: Serialize>( data: &[T], format: &FileFormat, filename_prefix: &str, ) -> Result<String>
Save data to a file in the data directory.
Files are saved to the data/ directory (created if it doesn’t exist) with a timestamp in the filename.
§Arguments
data- Data to save (must implement Serialize)format- File format to save as (FileFormat::Jsonfor JSON orFileFormat::Csvfor CSV)filename_prefix- Prefix for the filename. The final filename will be{prefix}_{timestamp}.{extension}
§Errors
std::io::Error- If the file cannot be opened or written to, or if the data directory cannot be createdserde_json::Error- If the JSON cannot be serialized
§Returns
Result<String>- Full path to the saved file (e.g.,data/recent_tracks_20240101_120000.json)
Sourcepub fn append<T: Serialize + for<'de> Deserialize<'de> + Clone>(
data: &[T],
file_path: &str,
) -> Result<String>
pub fn append<T: Serialize + for<'de> Deserialize<'de> + Clone>( data: &[T], file_path: &str, ) -> Result<String>
Append data to an existing file.
§Arguments
data- Data to appendfile_path- Path to the file to append to
§Returns
Result<String>- Path of the updated file
Append data to an existing file.
§Arguments
data- Data to appendfile_path- Path to the file to append to
§Errors
std::io::Error- If an I/O error occurs
§Returns
Result<String>- Path of the updated file
Auto Trait Implementations§
impl Freeze for FileHandler
impl RefUnwindSafe for FileHandler
impl Send for FileHandler
impl Sync for FileHandler
impl Unpin for FileHandler
impl UnwindSafe for FileHandler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more