https://github.com/artichoke/sysdir-rs
🍎 📁 Rust bindings to `sysdir` API on Apple platforms
https://github.com/artichoke/sysdir-rs
artichoke bindgen ios knownfolders macos rust rust-crate sysdir tvos watchos
Last synced: about 2 months ago
JSON representation
🍎 📁 Rust bindings to `sysdir` API on Apple platforms
- Host: GitHub
- URL: https://github.com/artichoke/sysdir-rs
- Owner: artichoke
- License: apache-2.0
- Created: 2023-05-12T06:00:14.000Z (about 2 years ago)
- Default Branch: trunk
- Last Pushed: 2025-04-01T00:15:53.000Z (about 2 months ago)
- Last Synced: 2025-04-01T01:25:43.011Z (about 2 months ago)
- Topics: artichoke, bindgen, ios, knownfolders, macos, rust, rust-crate, sysdir, tvos, watchos
- Language: Rust
- Homepage: https://crates.io/crates/sysdir
- Size: 1.7 MB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# sysdir-rs
[](https://github.com/artichoke/sysdir-rs/actions)
[](https://discord.gg/QCe2tp2)
[](https://twitter.com/artichokeruby)
[](https://crates.io/crates/sysdir)
[](https://docs.rs/sysdir)
[](https://artichoke.github.io/sysdir-rs/sysdir/)Enumeration of the filesystem paths for the various standard system directories
where apps, resources, etc. get installed.This crate exposes Rust bindings to the `sysdir(3)` library functions provided
by `libSystem.dylib` on macOS, iOS, tvOS, and watchOS.The `sysdir` API first appeared in OS X 10.12, iOS 10, watchOS 3 and tvOS 10
replacing the deprecated `NSSystemDirectories(3)` API.## Usage
Add this to your `Cargo.toml`:
```toml
[dependencies]
sysdir = "1.2.2"
```Then resolve well-known directories like this:
```rust
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::();
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");
}
}
```You can test this crate works on your platform by running the example:
```shell
cargo run --example enumerate_system_dirs
```## Implementation
sysdir-rs binds directly to `libSystem` with vendored bindings generated by
[`bindgen`][rust-bindgen]. This crate has no dependencies other than
`libSystem`.[rust-bindgen]: https://rust-lang.github.io/rust-bindgen/
Note that this crate is completely empty on non-Apple platforms.
## `no_std`
sysdir-rs is `no_std` and only requires `core`.
## Minimum Supported Rust Version
This crate requires at least Rust 1.64.0. This version can be bumped in minor
releases.## License
`sysdir-rs` is distributed under the terms of either the
[MIT License](LICENSE-MIT) or the
[Apache License (Version 2.0)](LICENSE-APACHE).