https://github.com/cdown/filestruct
Derive macro to read from a directory into a Rust struct.
https://github.com/cdown/filestruct
derive-macro files filesystem proc-macro rust rust-lang struct
Last synced: 9 months ago
JSON representation
Derive macro to read from a directory into a Rust struct.
- Host: GitHub
- URL: https://github.com/cdown/filestruct
- Owner: cdown
- License: mit
- Created: 2023-04-22T02:28:11.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-08T06:17:06.000Z (over 1 year ago)
- Last Synced: 2025-05-13T01:05:12.584Z (9 months ago)
- Topics: derive-macro, files, filesystem, proc-macro, rust, rust-lang, struct
- Language: Rust
- Homepage:
- Size: 35.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filestruct | [](https://github.com/cdown/filestruct/actions?query=branch%3Amaster)
A Rust derive macro which permits reading struct values from a directory.
Not ready for production use, still in heavy development and many things are
not yet implemented or will unexpectedly blow up.
## Usage
```rust
use filestruct::FromDir;
#[derive(FromDir, Debug)]
struct Files {
comm: String,
#[filestruct(file = "comm", trim = true)]
comm_trimmed: String,
oom_score: u32,
does_not_exist: Option,
#[filestruct(file = "oom_score_adj")]
does_not_exist_but_renamed: Option,
#[filestruct(relative_dir = "..", trim = true)]
uptime: String,
}
fn main() {
let files = Files::from_dir("/proc/self");
println!("{:#?}", files);
}
```
Results in:
```rust
Ok(
Files {
comm: "pdm-bin\n",
comm_trimmed: "pdm-bin",
oom_score: 800,
does_not_exist: None,
does_not_exist_but_renamed: Some(
200,
),
uptime: "177405.74 822813.82",
},
)
```
## Releases
Releases are a little complicated because filestruct_derive and filestruct are
separate crates. Use `cargo release`:
```
cargo release --execute -- minor
```