Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
rust-analyzer.github.io
#9180 fix some IDE functionality inside attribute macros. #9239 fix coercion in match with expected type. #9182 don’t complete derive macros as function-like macros. #9187 fix edge case in import granularity guessing. #9186 prefer attr macros in "Expand macro recursively". #9191 don’t descend into MacroCall TokenTree delimiters...
Project/Tooling Updates 2021-06-16 ~1 min read
cloudhead.io
...sources.wait(&mut events)?; for (key, event) in events.iter() { match key { Source::Listener => loop { // Accept as many connections as we can. let (conn, addr) = match listener.accept() { Ok((conn, addr)) => (conn, addr), Err(e) if e.kind() == io::ErrorKind::WouldBlock => break, Err(e) => return Err(e), }; // Register the new...
News & Blog Posts 2020-07-21 ~6 min read
github.com
...Since we already allow recursion via const fn and termination of said recursion via `if` or `match`, all code enabled by const recursion is already legal now. Some algorithms are better expressed as imperative loops and a lot of Rust code uses loops instead of recursion. Allowing loops in constants...
RFC 2344 RFC 2018-02-18 ~2 min read
mortenvistisen.com
...Tera = { 10 let mut tera = match Tera::new("templates/**/*.html") { 11 Ok(t) => t, 12 Err(e) => { 13 println!("Parsing error(s): {}", e); 14 ::std::process::exit(1); 15 } 16 }; 17 tera.autoescape_on(vec![".html", ".sql"]); 18 tera 19 }; 20} 21 22pub fn start_blog(listener: TcpListener) -> Result<Server...
Rust Walkthroughs 2022-09-07 ~24 min read
doc.rust-lang.org
...In the following example, surrounding the matcher with $(...),+ will match one or more expression, separated by commas. Also note that the semicolon is optional on the last case. // `find_min!` will calculate the minimum of any number of arguments. macro_rules! find_min { // Base case: ($x:expr) => ($x); // `$x` followed...
Rust by Example Book 2024-01-01 ~1 min read
www.ntietz.com
...It's just a big old match statement. We check the byte that's passed in and we return the appropriate value. pub fn parse_system_realtime(status_byte: u8) -> SystemRealtime { match status_byte { 0xf8 => SystemRealtime::Clock, 0xf9 => SystemRealtime::Tick, 0xfa => SystemRealtime::Start, 0xfb => SystemRealtime::Continue, 0xfc => SystemRealtime::Stop, 0xfe...
Rust Walkthroughs 2024-12-11 ~16 min read
ochagavia.nl
...the code used is_some() followed by unwrap(), instead of pattern matching, to extract the option’s inner value. Maybe the code was written before pattern matching was even introduced to the language, and I was the first one to notice it could be improved (language changes were routine in...
Observations/Thoughts 2024-03-13 ~2 min read
priver.dev
...Serialize>(t: &T) { let serialized = serde_json::to_string(t).unwrap(); println!("{}", serialized); } pub async fn new(db_url: &str) -> Result<Box<dyn DatabaseDriver>> { if db_url.starts_with("libsql") { let token = match config::database_token() { Ok(t) => t, Err(err) => bail!("{}", err), }; let client = match libsql::LibSQLDriver::new(db...
Rust Walkthroughs 2023-12-20 ~8 min read
rust-analyzer.github.io
...UnevaluatedConst before trait solving. #14890 use ::core instead of $crate in option_env! expansion. #14893 fix need-mut false positive in closure capture of match scrutinee. #14874 change how #![cfg(FALSE)] behaves on crate root. #14895 don’t try to determine type of token inside macro calls. #14904 render size...
Project/Tooling Updates 2023-05-31 ~1 min read
rust-analyzer.github.io
...left braces. #16822 improve resolution for inlay hints targeting the same position. #16871, #16886 skip problematic cyclic dev-dependencies. #16885 improve parser recovery for match arms. #16812 fix "Go to implementation" for impls inside blocks. #16909 keep the Attr::Literal spans. #16911 fix hang on projects depending on rustc_private.
Project/Tooling Updates 2024-03-27 ~1 min read
www.christopherbiscardi.com
...because if has a return value, the type of the return value from both branches has to match. By not writing an else branch, we've declared the return value from the non-existent else branch to be (), which doesn't match with the return type of the if branch...
Learn Standard Rust 2020-08-26 ~2 min read
github.com
...If you publish a crate with a `cfg(windows)` dependency then crates.io could expand this to all known triples which match `cfg(windows)` when storing the metadata internally. This would mean that crates using `cfg` syntax would continue to be compatible with older versions of Cargo so long as...
RFC 1361 RFC 2015-11-10 ~4 min read
oxc.rs
...These 200 bytes have to be passed around, and also accessed every time we do a matches!(expr, Expression::Variant(_)) check, which is not very cache friendly for performance.So to make memory access efficient, it is best to box the enum variants.The perf-book describes additional info on...
Project/Tooling Updates 2024-10-09 ~18 min read
guillaume-be.github.io
...A difference is made between the DAG nodes that do exist in the SentencePiece model (marked as leaves) and the nodes that do not have a matching. Every token is pushed by being added to the children of the token containing all characters except the last one: Get the characters...
News & Blog Posts 2020-06-10 ~19 min read
steveklabnik.com
...Record = result?; let replacement = args.replacement.clone(); match &*args.column_name { "name" => record.name = replacement, "surname" => record.surname = replacement, "city" => record.city = replacement, "country" => record.country = replacement, _ => panic!("incorrect column name"), } wtr.serialize(record)?; } wtr.flush()?; Ok(()) } fn main() { let opt = Opt::from_args(); if let Err(err) = run(&opt...
News & Blog Posts 2018-02-20 ~4 min read
github.com
...possible extensions ### `match_cfg` The original version of this RFC was more expansive, and proposed a `match_cfg` macro that provided some additional checking. The `match_cfg` macro takes a sequence of `cfg` patterns, followed by `=>` and an expression. Its syntax and semantics resembles that of `match`. However, there are...
RFC 1868 RFC 2016-11-15 ~20 min read
amitdev.github.io
...Int) -> bool { match op { Add => x <= y, Sub => x > y, Mul => x != 1 && y != 1 && x <= y, Div => y > 1 && ((x % y) == 0), } } fn apply(op: &Op, x: Int, y: Int) -> Int { match op { Add => x + y, Sub => x - y, Mul => x * y, Div => x / y, } } Apart from syntax, no...
Learn More Rust 2020-08-04 ~7 min read
jsdw.me
...fn poll(&mut self) -> Result<Async<u8>, io::Error> { let mut buf = [0;1]; match self.0.poll_read(&mut buf) { Ok(Async::Ready(_num_bytes_read)) => Ok(Async::Ready(buf[0])), Ok(Async::NotReady) => Ok(Async::NotReady), Err(e) => Err(e) } } } // Now we can use the above to create...
News & Blog Posts 2018-11-27 ~9 min read
doc.rust-lang.org
...Examples: # let (a, b, c) = (0, 1, 2); // For if branches let bar = if true { a } else if false { b } else { c }; // For match arms let baw = match 42 { 0 => a, 1 => b, _ => c, }; // For array elements let bax = [a, b, c]; // For closure with multiple return statements let clo...
The Rust Reference Book 2024-01-01 ~7 min read
kerkour.com
...String, } #[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let cli_matches = App::new("Rust to the mooooon") .version("1.0") .arg( Arg::with_name("concurrency") .short("c") .long("concurrency") .help("Number of concurrent inserts") .default_value("3"), ) .arg( Arg::with_name("inserts") .short("i") .long("inserts...
Observations/Thoughts 2021-08-04 ~5 min read
"As usual, the borrow checker is correct: we are doing memory crimes."

Search tips

Type anything to search across articles, videos (including conference talks), podcasts, research, crates, and Rust API documentation. These operators give you finer control — click an example to try it.

Find pages containing all your words. Pages where the words appear together rank higher.
Quote part of your query to keep those words together as an exact phrase within a larger search.
Wrap the whole query in quotes for a verbatim search that matches text exactly, punctuation and all — perfect for Rust syntax. Needs at least 3 characters.
Limit results to a single site. Works on its own () too. One site: per search.

Use the tabs and filters above the results to narrow by content type, publication year, and sort order.