Browser Support Test — Rust source
Audit your real browser against 30 modern web capabilities - WebGPU, WASM, WebAuthn, Service Workers and more. Get a weighted readiness score, copy-paste detection snippets, and a shareable link.
This is the Rust implementation — the same logic the interactive tool runs, in a shareable, citable form.
// Browser Support Test — target capability probe, weighted score, tier.
//
// Language: Rust
// CosmoDev polyglot showcase port of the `browser-support-test` tool.
// Ported from src/tools/BrowserSupportTest.tsx (+ browser-support/* modules) —
// display source, part of CosmoDev's polyglot tool pages.
//
// ILLUSTRATIVE PORT: the live tool detects *browser* features at runtime
// (navigator/window probes) — a browser-only concern that cannot run in a
// native Rust process. This port shows the ANALOGOUS pattern for a Rust
// build: it probes compile-time `cfg` keys (target arch, OS, CPU features,
// stdlib availability) — the mechanism Rust uses to gate platform features.
// The scoring algorithm and tier thresholds below are byte-for-byte the same
// as the TypeScript lib's; only the probe targets differ.
const SUPPORTED: &str = "supported";
const UNSUPPORTED: &str = "unsupported";
const LIMITED: &str = "limited";
const UNKNOWN: &str = "unknown";
/// contribution × weight. Same values as src/tools/browser-support/score.ts.
fn contribution(status: &str) -> f64 {
match status {
"supported" => 1.0,
"limited" => 0.5,
"needs-https" => 0.3,
_ => 0.0, // unsupported, unknown
}
}
#[derive(Clone)]
struct Check {
id: &'static str,
title: &'static str,
category: &'static str,
weight: f64,
/// Returns true when the capability is present in THIS build.
probe: fn() -> bool,
}
struct FeatureResult {
id: &'static str,
status: &'static str,
}
/// Weighted readiness 0–100; matches computeScore() exactly.
fn compute_score(results: &[FeatureResult], checks: &[Check]) -> i32 {
let mut earned = 0.0_f64;
let mut possible = 0.0_f64;
for r in results {
// Look up this result's weight in the catalog (skip unknown ids).
if let Some(c) = checks.iter().find(|c| c.id == r.id) {
earned += contribution(r.status) * c.weight;
possible += c.weight;
}
}
if possible == 0.0 {
0
} else {
(earned / possible * 100.0).round() as i32
}
}
/// tier_for mirrors tierFor() in the island — same thresholds.
fn tier_for(score: i32) -> (&'static str, &'static str) {
match score {
s if s >= 90 => ("Fully modern", "text-success"),
s if s >= 75 => ("Very capable", "text-success"),
s if s >= 55 => ("Capable, minor gaps", "text-accent"),
s if s >= 35 => ("Showing its age", "text-fg-muted"),
_ => ("Legacy browser", "text-danger"),
}
}
// Representative catalog of cfg-gated capabilities. cfg!() is resolved at
// compile time from the target triple + enabled feature flags — Rust's
// equivalent of `'feature' in window`.
fn checks() -> Vec<Check> {
vec![
Check { id: "target-arch", title: "Target arch", category: "Platform", weight: 1.0, probe: || cfg!(target_pointer_width = "64") },
Check { id: "unix", title: "Unix target", category: "Platform", weight: 2.0, probe: || cfg!(unix) },
Check { id: "wasm", title: "WASM target", category: "Platform", weight: 2.0, probe: || cfg!(target_arch = "wasm32") },
Check { id: "sse2", title: "SSE2", category: "Cpu", weight: 2.0, probe: || cfg!(target_feature = "sse2") },
Check { id: "avx2", title: "AVX2", category: "Cpu", weight: 2.0, probe: || cfg!(target_feature = "avx2") },
Check { id: "neon", title: "NEON", category: "Cpu", weight: 2.0, probe: || cfg!(target_feature = "neon") },
Check { id: "atomics", title: "Atomic ops", category: "Runtime", weight: 3.0, probe: || cfg!(target_has_atomic = "ptr") },
]
}
/// Run probes; a panic degrades to 'unknown' so one failure can't abort the audit.
fn run_checks(checks: &[Check]) -> Vec<FeatureResult> {
checks
.iter()
.map(|c| {
let status = std::panic::catch_unwind(std::panic::AssertUnwindSafe((c.probe)()))
.map(|ok| if ok { SUPPORTED } else { UNSUPPORTED })
.unwrap_or(UNKNOWN);
FeatureResult { id: c.id, status }
})
.collect()
}
fn main() {
let checks = checks();
let results = run_checks(&checks);
let score = compute_score(&results, &checks);
let (label, _) = tier_for(score);
let supported = results.iter().filter(|r| r.status == SUPPORTED).count();
println!(
"{} on {}/{}",
env!("CARGO_PKG_NAME"),
std::env::consts::OS,
std::env::consts::ARCH
);
println!(
"{}/{} capabilities · readiness {} · {}",
supported,
results.len(),
score,
label
);
// Silence unused warning when LIMITED is intentionally absent from probes.
let _ = LIMITED;
}
Also available in 13 other languages
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →