ic-query-cli 0.104.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Module: nns::topology::percent
//!
//! Responsibility: select NNS topology percentage totals and unavailable-value text.
//! Does not own: percentage arithmetic, report construction, or text tables.
//! Boundary: admits exact totals and delegates percentage rendering to Host Text.

/// Format known and unknown relationship counts as a nearest-tenth percentage.
#[must_use]
pub(super) fn coverage_percent_text(known: usize, unknown: usize) -> String {
    let Some(total) = known.checked_add(unknown) else {
        return "-".to_string();
    };
    let (Ok(known), Ok(total)) = (u64::try_from(known), u64::try_from(total)) else {
        return "-".to_string();
    };
    ratio_percent_text(known, total)
}

/// Format a ratio as a nearest-tenth percentage, preserving unavailable totals.
#[must_use]
pub(super) fn ratio_percent_text(numerator: u64, denominator: u64) -> String {
    ic_host_text::percent::ratio_percent_text(numerator, denominator)
        .unwrap_or_else(|| "-".to_string())
}

#[cfg(test)]
mod tests;