cosmic-files/examples/copy.rs
Vukašin Vojinović d5dbcc7677 chore: add rustfmt config
Also adds a Zed editor config for automatic formatting with nightly.
2026-04-29 00:53:57 +02:00

52 lines
1.6 KiB
Rust

use cosmic_files::operation::recursive::{Context, Method};
use cosmic_files::operation::{Controller, ReplaceResult};
use std::error::Error;
use std::io;
use std::path::PathBuf;
#[compio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let mut context = Context::new(Controller::default())
.on_progress(|op, progress| {
println!("{:?}: {:?}", op.to, progress);
})
.on_replace(|op, conflicting_count| {
Box::pin(async move {
println!(
"replace {:?}? (y/N) [conflicting: {}]",
op.to, conflicting_count
);
let mut line = String::new();
match io::stdin().read_line(&mut line) {
Ok(_) => {
if line == "y" {
ReplaceResult::Replace(false)
} else {
ReplaceResult::Skip(false)
}
}
Err(err) => {
eprintln!("failed to read stdin: {}", err);
ReplaceResult::Cancel
}
}
})
});
context
.recursive_copy_or_move(
vec![(PathBuf::from("test/a"), PathBuf::from("test/b"))],
Method::Copy,
)
.await?;
context
.recursive_copy_or_move(
vec![(PathBuf::from("test/b"), PathBuf::from("test/c"))],
Method::Move {
cross_device_copy: false,
},
)
.await?;
Ok(())
}