{"id":15893888,"url":"https://github.com/chinanf-boy/fs_extra_try","last_synced_at":"2025-04-02T18:16:27.221Z","repository":{"id":90548321,"uuid":"136620427","full_name":"chinanf-boy/fs_extra_try","owner":"chinanf-boy","description":"tour-example: fs_extra - Rust { Learn }","archived":false,"fork":false,"pushed_at":"2018-06-10T01:17:54.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T08:47:14.479Z","etag":null,"topics":["explain","try"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chinanf-boy.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-08T13:09:17.000Z","updated_at":"2019-05-17T02:31:13.000Z","dependencies_parsed_at":"2023-07-18T11:00:12.186Z","dependency_job_id":null,"html_url":"https://github.com/chinanf-boy/fs_extra_try","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Ffs_extra_try","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Ffs_extra_try/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Ffs_extra_try/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chinanf-boy%2Ffs_extra_try/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chinanf-boy","download_url":"https://codeload.github.com/chinanf-boy/fs_extra_try/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246866100,"owners_count":20846496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["explain","try"],"created_at":"2024-10-06T08:14:00.354Z","updated_at":"2025-04-02T18:16:27.202Z","avatar_url":"https://github.com/chinanf-boy.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## fs_extra\n\n尝试 `fs_extra` 库 「rust」 示例\n\n---\n\nhttps://github.com/webdesus/fs_extra\n\n### Example\n\n``` rust\nuse std::path::Path;\nuse std::{thread, time};\nuse std::sync::mpsc::{self, TryRecvError};\n\nextern crate fs_extra;\nuse fs_extra::dir::*;\nuse fs_extra::error::*;\n\nfn example_copy() -\u003e Result\u003c()\u003e {\n\n    let path_from = Path::new(\"./temp\"); // temp 路径\n    let path_to = path_from.join(\"out\"); // temp + out 路径\n    let test_folder = path_from.join(\"test_folder\"); // temp + test_folder 路径\n    let dir = test_folder.join(\"dir\"); // test_folder + dir 路径\n    let sub = dir.join(\"sub\");\n    let file1 = dir.join(\"file1.txt\");\n    let file2 = sub.join(\"file2.txt\");\n\n    create_all(\u0026sub, true)?; // 创建\n    create_all(\u0026path_to, true)?;\n    fs_extra::file::write_all(\u0026file1, \"content1\")?; // 写入\n    fs_extra::file::write_all(\u0026file2, \"content2\")?;\n\n    assert!(dir.exists()); // 参数如果是错误, 会 抛出错误❌\n    assert!(sub.exists());\n    assert!(file1.exists());\n    assert!(file2.exists());\n\n\n    let mut options = CopyOptions::new(); // 可用于配置文件将如何复制或移动的选项和标志。\n    options.buffer_size = 1;\n    let (tx, rx) = mpsc::channel(); // 通道\n    thread::spawn(move || { // 线程\n        let handler = |process_info: TransitProcess| {\n            tx.send(process_info).unwrap(); // 通道发送\n            thread::sleep(time::Duration::from_millis(2)); // 线程等待\n            fs_extra::dir::TransitProcessResult::ContinueOrAbort //如果进程没有错误，则继续执行进程，如果进程内容错误则继续进行。\n            //https://docs.rs/fs_extra/*/fs_extra/dir/enum.TransitProcessResult.html\n        };\n        // 分进程-复制, 从 test_folder 到 out 目录 全复制\n        copy_with_progress(\u0026test_folder, \u0026path_to, \u0026options, handler).unwrap();\n        // https://docs.rs/fs_extra/*/fs_extra/dir/fn.copy_with_progress.html\n    });\n\n    loop {\n        match rx.try_recv() { // 通道接收\n            Ok(process_info) =\u003e {\n                println!(\"{} of {} bytes\",\n                         process_info.copied_bytes,\n                         process_info.total_bytes);\n            }\n            Err(TryRecvError::Disconnected) =\u003e {\n                println!(\"finished\");\n                break;\n            }\n            Err(TryRecvError::Empty) =\u003e {}\n        }\n    }\n    Ok(())\n\n}\nfn main() {\n    example_copy().expect(\"Error handle filess\");\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinanf-boy%2Ffs_extra_try","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchinanf-boy%2Ffs_extra_try","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchinanf-boy%2Ffs_extra_try/lists"}