sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
# Structural conventions

This document is the reference for where code goes and how it is split. The
goal is that a change in one domain or backend does not require touching the
others.

## Directory map

```text
src/
├── lib.rs              # crate attributes, public module wiring, Error re-export
├── internal/           # crate-only helpers
│   ├── reexports.rs    # backend-facing re-exports
│   ├── fuzzing.rs      # hidden fuzzing helpers (Linux + fuzzing feature)
│   └── tests.rs        # crate-level compatibility tests
├── prelude.rs          # convenience re-exports only
├── common/             # types shared by several domains (DiskUsage, Uid, Gid)
├── component/          # public API: Component, Components
├── disk/               # public API: Disk, Disks, DiskKind, DiskRefreshKind
├── hardware/           # inventory: firmware, PCI, USB, power, sensors, displays, storage
├── gpu/                # public API: Gpu, Gpus, PCI + vendor data
├── network/            # public API: Networks, NetworkData, addresses
├── system/             # public API: System, Process, Cpu, Pid, refresh kinds
├── user/               # public API: User, Group, Users, Groups
├── support/            # internals: error, debug/, macros, utils, serde
└── platform/           # OS backends, selected as `crate::sys`
    ├── mod.rs          # cfg_select! dispatch
    ├── linux/          # Linux + Android
    ├── freebsd/  netbsd/
    ├── windows/
    ├── unix/           # shared Unix helpers (users, groups, errno, utils)
    ├── bsd/            # shared FreeBSD/NetBSD helpers
    └── apple/          # shared macOS/iOS internals + platform overrides
```

## Backend layout

Platform modules are hierarchical and split by responsibility:

- `apple/`: `cpu/{brand,frequency,usage,tests}`, `disk/{inner,list,new,properties}`,
  `gpu/{info,inner,pci}`, `process/{inner,status}`, `system/{cpu,memory,process,info_methods}`,
  `utils/{io,sysctl}`, `ffi/{objc,mach}`, `sandbox/`, and
  `macos/{component/{arm/{client,sensor},x86/{io_service,smc}}, ffi/{disk,smc,hid},
  process/{cpu,info,list,update}}`.
- `bsd/`: `sysctl`, `network/{data,state}`, shared `component`, `gpu`,
  `system_common`, plus the shared `network_data` counters.
- `freebsd/disk/`, `netbsd/disk/`: `inner`, `io`, `list`, `values` (and
  `geom` on FreeBSD).
- `freebsd/utils/`, `netbsd/utils/`: `sysctl`, `strings`, and the OS-specific
  `kenv` or `process` helpers.
- `linux/`: `cpu/{wrapper,values,inner,frequency,topology}`, `motherboard/{dmi,device_tree}`,
  `network/{data,state,sysfs,tests}`, `system/{cpu,memory,process,state,info_methods}`
  and `utils/{fs,parse}`.
- `windows/`: `cpu/{query,topology,vendor}`, `disk/{device,enumerate,inner,volume}`,
  `ffi/smbios/{table,types}`, `gpu/{adapter,devices,pdh}`, `network/{data,state,table}`,
  `process/{accessors,lifecycle,params/{cmdline,env,paths,read}}`, `system/{cpu,info,memory,process,registry}`
  and `users/{groups}`.
- `network_data/`: shared interface counters and snapshots used by every backend.
- `gpu/vendor/`: lookup plus `ids/` ranges (`below_1000`, `range_*`).

`docs/` never contains build-critical code. Usage guides live in
`docs/snippets/`; architecture, structure and API references live in
`docs/en/` and `docs/es/`.


## Where to find things

| You are looking for | File |
|---|---|
| Public module wiring | `src/lib.rs` |
| Internal re-exports | `src/internal/reexports.rs` |
| Fuzzing helpers | `src/internal/fuzzing.rs` |
| Crate-level tests | `src/internal/tests.rs` |
| Public re-exports | `src/prelude.rs` |
| System/process/CPU API | `src/system/` |
| Disk, component, GPU, network, user, hardware API | `src/{disk,component,gpu,network,user,hardware}/` |
| Shared IDs and usage types | `src/common/` |
| Linux OS wrappers | `src/platform/linux/ffi/{system,disk}.rs` |
| Unix network wrappers | `src/platform/unix/ffi/network.rs` |
| Windows network wrappers | `src/platform/windows/ffi/network.rs` |
| Apple/BSD FFI bindings | `src/platform/<os>/ffi/` |
| Windows SMBIOS parsing | `src/platform/windows/ffi/smbios/` |
| PCI vendor IDs | `src/gpu/vendor/ids/` |
| Error type | `src/support/error.rs` |
| Debug implementations | `src/support/debug/` |
| Unsafe implementation details | only `src/platform/` |
| API reference | `docs/en/api.md` |
| PCI vendor reference | `docs/en/reference/pci-vendor-ids.md` |
| Security/FFI rules | `docs/en/security.md` |

## Layer rules

| Layer | May depend on | Must not depend on |
|---|---|---|
| `lib.rs`, `prelude.rs` | public modules, `support::Error` | platform internals |
| domain modules (`system`, `disk`, ...) | `common`, `support`, `crate::sys` | other domains |
| `common` | `support` | domains or platform backends |
| `platform::*` | `support`, `common`, shared platform modules | public domain modules |
| `support` | std, optional external crates | domains or platform backends |

Each domain is behind its Cargo feature. A domain must compile with only its
own feature enabled; never reference a type from another optional domain unless
it lives in `common` or is re-exported by `crate::sys`.

## File split rules

- `mod.rs` is wiring only: `mod` declarations, visibility and re-exports.
- Public API: one type per file when the domain has several types
  (`sensor.rs`, `drive.rs`, `kind.rs`, `account.rs`, `group.rs`, ...).
- Collections (`Users`, `Groups`, `Disks`, `Components`, `Gpus`) use the
  `impl_collection_*!` macros for `Deref`/`DerefMut`/`IntoIterator`.
- Platform backends use:
  - `mod.rs`: exposed module and `cfg_select!` wiring.
  - `inner.rs`: `impl` blocks over `*Inner` types.
  - `helpers.rs` / `parse.rs` / `stats.rs`: pure helpers by responsibility.
  - `tests.rs`: unit tests.
- Split a file when it passes roughly 500–600 lines or mixes two
  responsibilities. Data tables are split by range, as in
  `gpu/vendor/ids/range_*`.
- Prefer exact names: `error.rs` for one error type, `sysctl.rs` for sysctl
  wrappers, `network/` for network code, `sandbox/` for restricted Apple
  stubs.
- Keep the shared Apple implementation in `platform/apple/`. It is used by
  both macOS and iOS; duplicating it would create two sources of truth.


## FFI safety boundary

Public domain modules (`system`, `disk`, `component`, `gpu`, `network`, `user`,
`hardware`, `common`) use `#![forbid(unsafe_code)]`. All OS access is behind
safe `platform` wrappers; unsafe blocks stay inside `platform/<os>/ffi/` and
must not expose raw pointers, unvalidated lengths or borrowed foreign handles.
Linux uses `platform/linux/ffi/`; shared Unix/Windows network wrappers live in
`platform/unix/ffi/network.rs` and `platform/windows/ffi/network.rs`.

Shared primitives (RAII handles, checked buffers, string conversion) live in the
platform modules; each wrapper returns its own concrete type instead of a
single generic response type.

## Dependency policy

- Keep the default dependency graph as small as possible: the Linux default
  build currently depends only on `libc`.
- Do not add a crate for something the standard library or the OS API can do
  directly. Prefer direct file reads, `libc` calls, Win32 and IOKit calls.
- Optional dependencies must be behind features and off by default
  (`serde`, `multithread`).
- Avoid wrapper crates in refresh/read paths; macros are compile-time and must
  expand to direct field access or direct calls.
- Dev-dependencies are allowed for tests and benchmarks only.
- Any new dependency must justify its binary size, compile time, MSRV,
  maintenance cost and why std/OS APIs are insufficient.

## Visibility rules

- Public API types: `pub`.
- Backend internals: `pub(crate)` only when another backend or domain needs
  them; otherwise `pub(super)`.
- No wildcard imports in new code. Wildcard re-exports are only allowed in
  `prelude`, `mod.rs` wiring, and the documented `support` hubs.
- `*Inner` types are implementation details and never appear in public
  signatures.

## Documentation rules

- Put usage guides in `docs/snippets/<domain>.md` and include them on the main
  type with `#[doc = include_str!("...")]`.
- Method docs describe the contract and semantic caveats in a few lines.
- Platform matrices, identifier formats and long examples belong in the guide,
  not in every method.
- Examples in guides use `rust,ignore`; they are documentation, not doctests.
- Runnable examples live in `tests/test.rs`; compile-failure cases are covered
  by unit tests or `trybuild` if they are added.
- There is no per-file license header; the license lives in `LICENSE`.
- Comments and doc comments are at most two lines; keep one line whenever the
  contract is obvious.

## Feature rules

- Domain features: `component`, `disk`, `gpu`, `network`, `system`, `user`.
- Cross-cutting features: `serde`, `multithread`, `debug`.
- Every domain must pass
  `cargo check --no-default-features --features <domain>`.
- Unsupported targets fail at compile time with `compile_error!`.

## Adding a domain

1. Create `src/<domain>/mod.rs` with the public types and re-exports.
2. Add the feature to `Cargo.toml` and the `pub mod` gate in `lib.rs`.
3. Add `*Inner` plus the `impl` in `platform/<os>/<domain>.rs`.
4. Unsupported targets fail at compile time with `compile_error!`.
5. Add a guide in `docs/snippets/<domain>.md` and a test in `tests/`.
6. Verify the isolated feature build and the full matrix.

## Adding a platform

1. Create `src/platform/<os>/` with domain modules.
2. Register it in `src/platform/mod.rs` with `cfg_select!` and expose `sys`.
3. Reuse `platform/unix`, `platform/bsd` or `platform/apple` when the code is
   genuinely shared.
4. Add CI coverage for the new target.

## Review checklist

- Does the change belong to a domain, `common`, `support` or `platform`?
- Does it compile with only the affected feature?
- Is the file under the split threshold and split by responsibility?
- Are docs short in the method and detailed in the guide?
- Are comments still at most two lines?