name_exchanger_rs 2.2.1

Atomically exchange names of two files or directories with Rust and C APIs
Documentation
  • Coverage
  • 36.36%
    4 out of 11 items documented0 out of 3 items with examples
  • Size
  • Source code size: 54.86 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 50s Average build duration of successful builds.
  • all releases: 52s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Mikachu2333/exchange_name_lib
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Mikachu2333

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

#include <stdint.h>

/// 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 exchange(const char* path1, const char* path2, bool preserve_ext);

Rust Interface

use std::path::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),
/// }
/// ```
fn exchange_rs(path1: &Path, path2: &Path, preserve_ext: bool) -> Result<(), RenameError>;

Example 示例

Ref to 参考

  1. name_exchanger

  2. rs-NameExchanger