#path #macos-ios #apple #api-bindings #app-dirs #no-alloc #known-folder

no-std sysdir

Rust 对 macOS、iOS、tvOS 和 watchOS 上的 sysdir(3) 的绑定

5 个稳定版本

1.2.2 2023 年 6 月 2 日
1.2.1 2023 年 5 月 14 日
1.1.0 2023 年 5 月 13 日
1.0.0 2023 年 5 月 12 日

#45 in macOS 和 iOS API

Download history 106/week @ 2024-03-14 95/week @ 2024-03-21 191/week @ 2024-03-28 170/week @ 2024-04-04 99/week @ 2024-04-11 94/week @ 2024-04-18 150/week @ 2024-04-25 103/week @ 2024-05-02 127/week @ 2024-05-09 154/week @ 2024-05-16 94/week @ 2024-05-23 153/week @ 2024-05-30 93/week @ 2024-06-06 99/week @ 2024-06-13 133/week @ 2024-06-20 149/week @ 2024-06-27

486 每月下载量

Apache-2.0 OR MIT

15KB
185 代码行

sysdir-rs

GitHub Actions Discord Twitter
Crate API API trunk

枚举各种标准系统目录的文件系统路径,其中应用程序、资源等被安装。

此 crate 揭示了由 macOS、iOS、tvOS 和 watchOS 上 sysdir(3) 库函数提供的 Rust 绑定。

sysdir API 首次出现在 OS X 10.12、iOS 10、watchOS 3 和 tvOS 10 中,取代了已废弃的 NSSystemDirectories(3) API。

用法

将此添加到您的 Cargo.toml

[dependencies]
sysdir = "1.2.2"

然后以这种方式解析已知目录

use core::ffi::{c_char, CStr};

use sysdir::*;

let mut path = [0; PATH_MAX as usize];

let dir = sysdir_search_path_directory_t::SYSDIR_DIRECTORY_USER;
let domain_mask = SYSDIR_DOMAIN_MASK_LOCAL;

unsafe {
    let mut state = sysdir_start_search_path_enumeration(dir, domain_mask);
    loop {
        let path = path.as_mut_ptr().cast::<c_char>();
        state = sysdir_get_next_search_path_enumeration(state, path);
        if state == 0 {
            break;
        }
        let path = CStr::from_ptr(path);
        let s = path.to_str().unwrap();
        assert_eq!(s, "/Users");
    }
}

您可以通过运行示例来测试此 crate 是否在您的平台上工作

cargo run --example enumerate_system_dirs

实现

sysdir-rs 直接绑定到 libSystem,并通过 bindgen 生成的 vendored 绑定。此 crate 除了 libSystem 外没有其他依赖项。

请注意,此 crate 在非 Apple 平台上完全为空。

no_std

sysdir-rs 是 no_std 且仅需要 core

最低支持的 Rust 版本

此 crate 需要 Rust 1.64.0 或更高版本。此版本可以在次要版本中提升。

许可证

sysdir-rs 根据 MIT 许可证Apache 许可证(版本 2.0) 分发。

无运行时依赖项