Share Rust snippets, ownership patterns, or trait implementations: highlighted and encrypted without needing a GitHub account.
1use std::collections::HashMap;23fn word_freq(text: &str) -> HashMap<&str, usize> {4 let mut counts = HashMap::new();5 for word in text.split_whitespace() {6 *counts.entry(word).or_insert(0) += 1;7 }8 counts9}1011fn top_n<'a>(12 counts: &'a HashMap<&str, usize>,13 n: usize,14) -> Vec<(&&'a str, &'a usize)> {15 let mut pairs: Vec<_> = counts.iter().collect();16 pairs.sort_unstable_by(|a, b| b.1.cmp(a.1));17 pairs.into_iter().take(n).collect()18}1920fn main() {21 let text = "the quick brown fox jumps over the lazy dog the fox";22 let counts = word_freq(text);23 for (word, count) in top_n(&counts, 3) {24 println!("{word}: {count}");25 }26}Paste Rust code and get a shareable link with full syntax highlighting, server-side rendered with no JavaScript overhead.
Deleted on first open. Can't be viewed twice.
Add a password for end-to-end encryption with no raw key stored.
Set pastes to expire after 1 hour, 1 day, 7 days, or up to 30 days. Gone when you say so.
No sign-up, no email, no ads. Paste and share in seconds.
Yes. The Shiki Rust grammar handles macro_rules!, procedural macros, and attribute macros.
Yes: use the TOML language option for Cargo.toml files.
Pastes up to 5 MB are supported.