### Access `VersionData` Runtime Information Source: https://context7.com/jplatte/caniuse.rs/llms.txt Shows how to retrieve and use `VersionData` at runtime, including filtering by version number and constructing URLs. Requires importing `VERSIONS`. ```rust use crate::data::VERSIONS; // Find version 1.31 let version = VERSIONS.iter().find(|v| v.number == "1.31"); if let Some(v) = version { println!("Release date: {:?}", v.release_date); // Some("2018-12-06") println!("Blog: {:?}", v.blog_post_path); // -> Some("2018/12/06/Rust-1.31-and-rust-2018/") // Build full URLs: if let Some(path) = v.blog_post_path { println!("https://blog.rust-lang.org/{path}"); } if let Some(id) = v.gh_milestone_id { println!("https://github.com/rust-lang/rust/milestone/{id}"); } } // Get all features that belong to 1.31 use crate::data::FEATURES; let features_1_31: Vec<_> = FEATURES.iter() .filter(|f| matches!(f.version, Some(v) if v.number == "1.31")) .collect(); ``` -------------------------------- ### Initialize WASM Application Source: https://context7.com/jplatte/caniuse.rs/llms.txt This JavaScript code initializes the WebAssembly module and runs the Yew application. It handles theme restoration, checks for WebAssembly support, and then mounts the Yew app into the main DOM element. ```javascript // src/main.js — bundled by rollup into public/caniuse_rs.js import init, { run } from '../pkg/caniuse_rs.js'; // Restore or detect preferred color theme let theme; try { theme = localStorage.getItem("theme"); } catch (_e) {} if (typeof theme !== "string") { theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; } document.documentElement.dataset.theme = theme; // sets data-theme="dark"|"light" // Load and start the WASM app (only if WebAssembly is supported) if ('WebAssembly' in window) { async function main() { await init('/caniuse_rs.wasm'); // fetch + instantiate the WASM module run(); // mount the Yew app into
} main(); } ``` -------------------------------- ### Mount Yew App in WASM Source: https://context7.com/jplatte/caniuse.rs/llms.txt This Rust snippet is the WASM entry point. It selects the main DOM element and renders the root Yew component into it. ```rust // src/lib.rs #[wasm_bindgen] pub fn run() { let page = document().query_selector("main").unwrap().unwrap(); yew::Renderer::::with_root(page).render(); } ``` -------------------------------- ### Generate Static Data Arrays (`build.rs`) Source: https://context7.com/jplatte/caniuse.rs/llms.txt Illustrates the static arrays generated by the build script for use at compile time. These include version data, feature data, and ngram search indices. ```rust pub static VERSIONS: &[VersionData] = &[ VersionData { number: "1.79", channel: Channel::Stable, release_date: Some("2024-06-13"), release_notes: None, blog_post_path: Some("2024/06/13/Rust-1.79.0/"), gh_milestone_id: Some(118), }, // ... all versions sorted newest-first ... ]; pub static FEATURES: &[FeatureData] = &[ FeatureData { title: "`io::Cursor::new` as `const fn`", flag: Some("const_io_structs"), slug: "const_io_cursor_new", version: Some(&VERSIONS[0]), impl_pr_id: Some(78811), tracking_issue_id: Some(78812), stabilization_pr_id: Some(124049), doc_path: Some("std/io/struct.Cursor.html#method.new"), items: &["std::io::Cursor::new"], // ... other optional fields as None ... }, // ... ]; // Ngram search indices — built at compile time: pub static FEATURE_MONOGRAM_INDEX: once_cell::sync::Lazy> = ...; pub static FEATURE_BIGRAM_INDEX: once_cell::sync::Lazy> = ...; pub static FEATURE_TRIGRAM_INDEX: once_cell::sync::Lazy> = ...; ``` -------------------------------- ### Development CLI Commands Source: https://context7.com/jplatte/caniuse.rs/llms.txt These bash commands utilize the `cargo xtask` helper for common development tasks such as building the site in development or release mode, serving it locally, and deploying it. ```bash # Build the site in development mode (fast, no optimizations) cargo xtask build --dev # Build in release mode (wasm-opt size optimizations via wasm-pack) cargo xtask build # Build and serve locally at http://localhost:8000 (development mode by default) cargo xtask serve # Build (release) and serve locally cargo xtask serve --release # Build (release) and deploy to caniuse.rs via rsync + ssh cargo xtask deploy ``` -------------------------------- ### Access `FeatureData` Runtime Information Source: https://context7.com/jplatte/caniuse.rs/llms.txt Demonstrates how to access and filter `FeatureData` at runtime using static arrays. Requires importing `FEATURES` and `Channel`. ```rust use crate::data::{FEATURES, Channel}; // Find a feature by slug let feature = FEATURES.iter().find(|f| f.slug == "conservative_impl_trait"); if let Some(f) = feature { println!("Title: {}", f.title); // "`impl Trait` in function return types" println!("Flag: {:?}", f.flag); // Some("conservative_impl_trait") println!("Version: {:?}", f.version.map(|v| v.number)); // Some("1.26") println!("Stable: {}", f.is_on_channel(Channel::Stable)); // true println!("Tracking issue: {:?}", f.tracking_issue_id); // Some(34511) } // Check all stable features let stable: Vec<_> = FEATURES.iter() .filter(|f| f.is_on_channel(Channel::Stable)) .collect(); // Check unstable (nightly-only) features — version is None let unstable: Vec<_> = FEATURES.iter() .filter(|f| f.version.is_none()) .collect(); ``` -------------------------------- ### TOML Metadata for Rust Versions Source: https://context7.com/jplatte/caniuse.rs/llms.txt Stores metadata for Rust versions, including release date, blog post path, and GitHub milestone ID. Each TOML file in `data/` must have a corresponding entry here. ```toml # data/versions.toml ["1.79"] release_date = "2024-06-13" gh_milestone_id = 118 blog_post_path = "2024/06/13/Rust-1.79.0/" ["1.31"] release_date = "2018-12-06" release_notes = "version-1310-2018-12-06" gh_milestone_id = 58 blog_post_path = "2018/12/06/Rust-1.31-and-rust-2018/" ``` -------------------------------- ### Execute Ngram-Weighted Search Source: https://context7.com/jplatte/caniuse.rs/llms.txt This snippet demonstrates how to perform a search using pre-allocated score buffers for efficiency. It extracts search terms and then runs the search, printing the results. The score buffer can be reused for subsequent searches. ```rust use crate::search::{extract_search_terms, run_search}; use crate::data::FEATURES; // Allocate a reusable score buffer (one entry per feature) let mut search_scores = vec![(0u16, 0.0f64); FEATURES.len()]; // Run a search let terms = extract_search_terms("impl trait").unwrap(); let results = run_search(&terms, &mut search_scores); for feature in &results { let version_str = feature.version.map(|v| v.number).unwrap_or("unstable"); println!("{} (since {})", feature.title, version_str); } // Example output: // `impl Trait` in function return types (since 1.26) // `impl Trait` in function arguments (since 1.26) // ... // The score buffer can be reused across searches for efficiency let terms2 = extract_search_terms("async").unwrap(); let results2 = run_search(&terms2, &mut search_scores); ``` -------------------------------- ### Static JSON API for Rust Features Source: https://context7.com/jplatte/caniuse.rs/llms.txt This JSON file is generated at build time and provides the complete feature dataset for external tooling. It is served at https://caniuse.rs/features.json. ```json { "versions": { "1.79": { "channel": "stable", "release_date": "2024-06-13", "gh_milestone_id": 118, "blog_post_path": "2024/06/13/Rust-1.79.0/" } }, "features": { "const_io_cursor_new": { "title": "`io::Cursor::new` as `const fn`", "flag": "const_io_structs", "impl_pr_id": 78811, "tracking_issue_id": 78812, "stabilization_pr_id": 124049, "items": ["std::io::Cursor::new"], "doc_path": "std/io/struct.Cursor.html#method.new", "version": "1.79" }, "conservative_impl_trait": { "title": "`impl Trait` in function return types", "flag": "conservative_impl_trait", "tracking_issue_id": 34511, "edition_guide_path": "rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html", "version": "1.26" } } } ``` -------------------------------- ### Define Client-Side Routes with Yew Router Source: https://context7.com/jplatte/caniuse.rs/llms.txt This enum defines the routes for the Yew application using `yew-router`. Each variant maps to a specific URL path and is associated with a corresponding component or view. ```rust #[derive(Clone, Debug, PartialEq, Routable)] enum AppRoute { #[at("/features/:name")] // Feature detail page → FeaturePage component Feature { name: String }, #[at("/versions/:number")] // Version detail page → VersionPage component Version { number: String }, #[at("/about")] // About page → About component About, #[at("/recent")] // Recently stabilized → Index (RecentlyStabilized mode) RecentlyStabilized, #[at("/unstable")] // Nightly features → Index (Unstable mode) Unstable, #[at("/")] // Search homepage → Index (Stable mode) Index, } // Example URLs: // https://caniuse.rs/ → Stable feature list + search // https://caniuse.rs/features/conservative_impl_trait → Feature detail // https://caniuse.rs/versions/1.31 → All features in Rust 1.31 // https://caniuse.rs/unstable → Nightly-only features // https://caniuse.rs/recent → Beta/recently-stabilized features ``` -------------------------------- ### Extract Search Terms (`src/search.rs`) Source: https://context7.com/jplatte/caniuse.rs/llms.txt Parses a query string into search terms, validating for backticks and non-ASCII characters. Returns an `Err(InvalidSearchQuery)` for invalid input. ```rust use crate::search::{extract_search_terms, InvalidSearchQuery}; // Valid queries assert_eq!(extract_search_terms("impl trait").unwrap(), vec!["impl", "trait"]); assert_eq!(extract_search_terms(" async await ").unwrap(), vec!["async", "await"]); assert_eq!(extract_search_terms("").unwrap(), Vec::::new()); // Invalid query (backtick or non-ASCII) assert!(extract_search_terms("`async`").is_err()); assert!(matches!(extract_search_terms("café"), Err(InvalidSearchQuery))); ``` -------------------------------- ### TOML Definition for Rust Feature Source: https://context7.com/jplatte/caniuse.rs/llms.txt Defines a Rust feature with its title, flag, and tracking information. All fields except title are optional. The filename serves as the URL slug. ```toml # data/1.26/conservative_impl_trait.toml title = "`impl Trait` in function return types" flag = "conservative_impl_trait" tracking_issue_id = 34511 edition_guide_path = "rust-2018/trait-system/impl-trait-for-returning-complex-types-with-ease.html" ``` ```toml # data/1.79/const_io_cursor_new.toml title = "`io::Cursor::new` as `const fn`" flag = "const_io_structs" impl_pr_id = 78811 tracking_issue_id = 78812 stabilization_pr_id = 124049 items = ["std::io::Cursor::new"] doc_path = "std/io/struct.Cursor.html#method.new" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.