use std::fmt;
use std::future::Future;
use std::io::Write;
use std::path::Path;
use std::sync::Arc;
use super::run;
use crate::Result;
use crate::pool::Pool;
pub use crate::backup::Backup;
impl super::Store {
pub fn backup(&self) -> BackupBuilder {
BackupBuilder { blocking: self.blocking().backup(), pool: Arc::clone(self.pool()) }
}
}
#[must_use = "a backup is made by write or write_to"]
pub struct BackupBuilder {
blocking: crate::backup::BackupBuilder,
pool: Arc<Pool>,
}
impl fmt::Debug for BackupBuilder {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.blocking, f)
}
}
impl BackupBuilder {
pub fn include(self, name: &str) -> Self {
BackupBuilder { blocking: self.blocking.include(name), pool: self.pool }
}
pub fn include_encryption_key(self) -> Self {
BackupBuilder { blocking: self.blocking.include_encryption_key(), pool: self.pool }
}
pub fn write(self, path: impl AsRef<Path>) -> impl Future<Output = Result<Backup>> + Send + 'static {
let (builder, path) = (self.blocking, path.as_ref().to_path_buf());
let what = format!("backup {}", path.display());
run::blocking(&self.pool, None, what, move || builder.write(path))
}
pub fn write_to(self, out: impl Write + Send + 'static) -> impl Future<Output = Result<Backup>> + Send + 'static {
let builder = self.blocking;
run::blocking(&self.pool, None, "backup".to_owned(), move || builder.write_to(out))
}
}
#[cfg(test)]
#[path = "backup_tests.rs"]
mod tests;