Expand description
htoprs — a faithful Rust port of htop.
The C source at ~/forkedRepos/htop (v3.5.1) is the spec. Every
function under ported ports a specific htop C function, cited
by <File>.c:<line> in its doc comment. The port-purity gate in
build.rs rejects any free fn under src/ported/ whose name
has no counterpart in the htop C source (snapshotted at
tests/data/htop_c_fn_names.txt).
§Clippy and faithful ports
CI runs cargo clippy --all-targets -- -D warnings. A handful of
idiom lints are allowed crate-wide because the flagged code is a
literal translation of the htop C source, and rewriting it into the
idiomatic Rust clippy prefers would either diverge from the spec or
change behavior:
needless_range_loop/explicit_counter_loop— dual-indexfor (i, j) …loops (strncpy,RichStringfills) mirror the C pointer walks; iterator rewrites lose the 1:1 line mapping.manual_div_ceil—(cpus + 1) / 2is the C half-split formula.implicit_saturating_sub—count > MAX ? count - MAX : 0is the C ternary;saturating_subreads differently from the source.manual_pattern_char_comparison— explicit\n/\rcompares match the C trailing-newline strip.neg_cmp_op_on_partial_ord—!(rate >= 0.0)is a deliberate NaN guard fromRow.c;rate < 0.0would treat NaN as valid.identity_op/int_plus_one— test assertions spell out the C arithmetic (0 + 0 - scrollV + 1,len >= n + 1) for clarity.doc_lazy_continuation— ported doc comments carry C-snippet bullet lists whose wrapped lines trip the lint.field_reassign_with_default— htop’s*_initroutines set fields one at a time on a freshlycalloc’d struct; the port mirrors that line-for-line rather than collapsing into a struct literal.unnecessary_unwrap—if x.is_some() { x.unwrap() }mirrors the Cif (ptr) { ptr->… }null-check-then-deref shape.manual_c_str_literals—b"kern.osrelease\0"are the literal C string constants passed tosysctlbyname;c"…"hides the NUL the source spells out.not_unsafe_ptr_arg_deref— ported helpers keep htop’s raw-pointer parameter signatures; marking themunsafewould change the API.too_many_arguments— ported functions keep htop’s C parameter lists verbatim.erasing_op— test assertions spell out C arithmetic that folds to zero ((-20 + 20) / 5= the nice→ioprio mapping) for clarity.needless_late_init— abufferdeclared then filled inside amatch/switchmirrors htop’schar* buffer; switch(field){…}.
Modules§
- extensions
- htoprs-original extensions.
- ported
- Faithful ports of htop C source files.
Macros§
- CRT_
debug - Port of the
CRT_debug(...)macro fromCRT.h:167–170. In debug builds (#elseof#ifdef NDEBUG) it forwards__FILE__/__LINE__plus the formatted arguments toCRT_debug_impl; in release (NDEBUG) it expands to nothing, discarding its arguments unevaluated exactly like the empty C#define CRT_debug(...). Rust has no stable__func__, so the function name passed toCRT_debug_implis empty.