fn save_to_file(&mut self, log: bool) {
        let serialized = serde_json::to_string(&self);
        if let Err(error) = serialized {
            error!("Failed to serialize state: {:?}", error);
            return;
        }

        let serialized = serialized.unwrap();

        let path = Path::new(&self.settings.shared.pueue_directory);
        let (temp, real) = if log {
            let path = path.join("log");
            let now: DateTime<Utc> = Utc::now();
            let time = now.format("%Y-%m-%d_%H-%M-%S");
            (
                path.join(format!("{}_state.json.partial", time)),
                path.join(format!("{}_state.json", time)),
            )
        } else {
            (path.join("state.json.partial"), path.join("state.json"))
        };

        // Write to temporary log file first, to prevent loss due to crashes.
        if let Err(error) = fs::write(&temp, serialized) {
            error!(
                "Failed to write log to directory. File permissions? Error: {:?}",
                error
            );
            return;
        }

        // Overwrite the original with the temp file, if everything went fine.
        if let Err(error) = fs::rename(&temp, &real) {
            error!(
                "Failed to overwrite old log file. File permissions? Error: {:?}",
                error
            );
            return;
        }

        if log {
            debug!("State backup created at: {:?}", real);
        } else {
            debug!("State saved at: {:?}", real);
        }
    }
/// Save the current state to disk.
/// We do this to restore in case of a crash.
/// If log == true, the file will be saved with a time stamp.
///
/// In comparison to the daemon -> client communication, the state is saved
/// as JSON for better readability and debug purposes.
Save the current state to disk.
We do this to restore in case of a crash.
If log == true, the file will be saved with a time stamp.

In comparison to the daemon -> client communication, the state is saved
as JSON for better readability and debug purposes.
Save the current state to disk . We do this to restore in case of a crash . If log == true the file will be saved with a time stamp . In comparison to the daemon - > client communication the state is saved as JSON for better readability and debug purposes .
fn save_to_file(&mut self, log: bool) {
        let serialized = serde_json::to_string(&self);
        if let Err(error) = serialized {
            error!("Failed to serialize state: {:?}", error);
            return;
        }
        let serialized = serialized.unwrap();
        let path = Path::new(&self.settings.shared.pueue_directory);
        let (temp, real) = if log {
            let path = path.join("log");
            let now: DateTime<Utc> = Utc::now();
            let time = now.format("%Y-%m-%d_%H-%M-%S");
            (
                path.join(format!("{}_state.json.partial", time)),
                path.join(format!("{}_state.json", time)),
            )
        } else {
            (path.join("state.json.partial"), path.join("state.json"))
        };
        // Write to temporary log file first, to prevent loss due to crashes.
        if let Err(error) = fs::write(&temp, serialized) {
            error!(
                "Failed to write log to directory. File permissions? Error: {:?}",
                error
            );
            return;
        }
        // Overwrite the original with the temp file, if everything went fine.
        if let Err(error) = fs::rename(&temp, &real) {
            error!(
                "Failed to overwrite old log file. File permissions? Error: {:?}",
                error
            );
            return;
        }
        if log {
            debug!("State backup created at: {:?}", real);
        } else {
            debug!("State saved at: {:?}", real);
        }
    }
fn save_to_file ( & mut self , log : bool ) { let serialized = serde_json :: to_string ( & self ) ; if let Err ( error ) = serialized { error ! ( " " error ) ; return ; } let serialized = serialized . unwrap ( ) ; let path = Path :: new ( & self . settings . shared . pueue_directory ) ; let ( temp , real ) = if log { let path = path . join ( " " ) ; let now : DateTime < Utc > = Utc :: now ( ) ; let time = now . format ( " " ) ; ( path . join ( format ! ( " " time ) ) , path . join ( format ! ( " " time ) ) , ) } else { ( path . join ( " " ) , path . join ( " " ) ) } ; // Write to temporary log file first, to prevent loss due to crashes. if let Err ( error ) = fs :: write ( & temp , serialized ) { error ! ( " " error ) ; return ; } // Overwrite the original with the temp file, if everything went fine. if let Err ( error ) = fs :: rename ( & temp , & real ) { error ! ( " " error ) ; return ; } if log { debug ! ( " " real ) ; } else { debug ! ( " " real ) ; } }
Save the current state to disk.
Save the current state to disk .
&mut self
log
bool