Name Exchanger Library (Rust)
A cross-platform library for atomically exchanging names of two files or directories, written in Rust.
一个使用Rust编写的跨平台库,用于原子性地交换两个文件或目录的名称。
Overview 概述
This library provides safe and atomic file/directory name exchanges through exposed C-compatible interfaces. It can be called from other languages like C/C++, Python, etc.
该库通过暴露的 C 兼容接口提供安全且原子性的文件/目录名称交换功能。可以从C/C++、Python等其他语言调用。
Usage 使用方法
C Interface
/// Exchange names of two files or directories
///
/// @param path1 - First file or directory path
/// @param path2 - Second file or directory path
/// @param preserve_ext - true: keep each file extension, false: swap full names including extension
/// @return 0 for success, non-zero values for errors:
/// 0 - Success
/// 1 - File does not exist
/// 2 - Permission denied
/// 3 - Target file already exists
/// 4 - Two paths refer to the same file
/// 5 - Invalid path (e.g. non-UTF-8)
/// 255 - Unknown error
int32_t ;
Rust Interface
use Path;
/// Exchange names of two files or directories
///
/// # Arguments
/// * `path1` - First file or directory path
/// * `path2` - Second file or directory path
/// * `preserve_ext` - true: keep each file extension, false: swap full names including extension
///
/// # Returns
/// * `Ok(())` - Success
/// * `Err(RenameError)` - Error
///
/// ## `RenameError` enum
/// ```rust
/// pub enum RenameError {
/// PermissionDenied,
/// AlreadyExists,
/// NotExists,
/// SamePath,
/// InvalidPath(String),
/// Unknown(String),
/// }
/// ```
;
Example 示例
Ref to 参考