Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
sunshowers.io
...break; } } }, recv(signal_receiver) -> internal_event => { match internal_event { // internal_event is a Result<SignalEvent, RecvError>. Ok(event) => InternalEvent::Signal(event), Err(_) => { // Ignore the signal thread being dropped. This is done for // noop signal handlers. continue; } } }, }; // ... process internal_event } If this loop received a test event, it would bubble that...
Observations/Thoughts 2022-10-05 ~19 min read
doc.rust-lang.org
...Because there may not be any matching element, select_first returns an Option<ElementRef>. Finally, we use the Option::map method, which lets us work with the item in the Option if it’s present, and do nothing if it isn’t. (We could also use a match expression here...
The Rust Programming Language Book 2024-02-01 ~14 min read
blog.codecentric.de
...While this does not completely match up with all the capabilities of the “init-check-update for loop”, it does very elegantly cover the most common use. More complex cases will need to be written out using while. Match 1fn match_it(x: Option<i32>, flag: bool) -> i32 { 2 match...
Learn Standard Rust 2020-09-16 ~37 min read
siciarz.net
...uint, primes: &Primes) -> Option<uint> { use std::iter::MultiplicativeIterator; match primes.factor(n) { Ok(factors) => Some(factors.into_iter().map(|(_, x)| x + 1).product()), Err(_) => None, } } The trick is to multiply all prime factor exponents, incremented before multiplication. See the explanation at Maths Challenge for the curious. So when we...
Blog Posts 2014-12-08 ~3 min read
coaxion.net
...gio::File) -> Result<(), String> { // Try to open the file let (_file, strm) = await!(file.read_async_future(glib::PRIORITY_DEFAULT)) .map_err(|(_file, err)| format!("Failed to open file: {}", err))?; Ok(())}fn main() { [...] let future = async_block! { match await!(read_file(file)) { Ok(()) => (), Err(err) => eprintln!("Got error: {}", err), } l...
News & Blog Posts 2018-04-24 ~13 min read
blog.merigoux.fr
...If the output of one test case matches, we can be a little bit more confident that our program is correct. But how can we be sure it will work in all situations? What if our test cases missed a corner case in our algorithm? One way to increase confidence...
News & Blog Posts 2019-04-16 ~9 min read
www.shuttle.rs
...The match keyword allows us to match the current event against a set of patterns. If the pattern matches, we execute the code in the corresponding branch. If the Result is Ok, we match against the XmlEvent::StartElement variant. This variant indicates that we are inside an opening tag. In...
Observations/Thoughts 2023-06-21 ~9 min read
github.com
...Gc<Monster>, room: &mut Room) { match room.find_random_exit() { None => { } Some(exit) => { victim.move_to_room(exit); } } } As before, we'll start out with a type of `Monster`, but this type the method `move_to_room()` has a receiver type of `Gc<Monster>`. This doesn't match cases 1...
RFC 48 RFC 2014-06-10 ~23 min read
rust-lang-nursery.github.io
...guess_format reads the leading magic bytes and returns the matching ImageFormat, which in turn gives the MIME type through ImageFormat::to_mime_type. Only the header is examined, so a short prefix of the file is enough. Inspect image EXIF metadata [![kamadak-exif-badge]][kamadak-exif] [![cat-multimedia-badge...
The Rust Cookbook Book 2024-01-01 ~1 min read
mender.io
...Through utilizing the pattern matching capabilities of Rust, the initial state-machine skeleton looks like: loop { let (state, action) = match (cur_state, cur_action) { (ExternalState::Init, Event::Uninitialized) => { match InitState::is_committed() { true => (ExternalState::Idle, Event::None), false => (ExternalState::Idle, Event::None), } } (ExternalState::Idle, _) if !client.is_authorized => { debug!("Client...
Learn More Rust 2020-08-18 ~11 min read
kmcallister.github.io
...main() { ::std::io::stdio::println_args( ::std::fmt::Arguments::new({ #[inline] #[allow(dead_code)] static __STATIC_FMTSTR: &'static [&'static str] = &["Hello, world!"]; __STATIC_FMTSTR }, &match () { () => [], })); } Freeze the shape of the tree Assign each node a unique NodeId Build an index by NodeId of AST nodes and their parents See libsyntax...
Blog Posts 2015-01-19 ~6 min read
blog.digital-horror.com
...Think of this as a simple client-server connection.loop { match socket.read(&mut buf).await { Ok(0) => returing, Ok(n) => { println!( "received {} bytes, msg: {}", n, String::from_utf8_lossy(buf.clone()[..n].to_vec().as_slice()) ); socket .write_all(&buf[..n]) .await .expect("failed to write data to socket...
Observations/Thoughts 2024-05-29 ~6 min read
gill.net.in
...u16, ) -> Option<(Device<T>, DeviceHandle<T>)> { let devices = match context.devices() { Ok(d) => d, Err(_) => return None, }; for device in devices.iter() { let device_desc = match device.device_descriptor() { Ok(d) => d, Err(_) => continue, }; if device_desc.vendor_id() == vid && device_desc.product_id() == pid { match device.open() { Ok(handle...
Learn More Rust 2020-08-04 ~14 min read
rust-lang-nursery.github.io
...of an array in parallel | [![rayon-badge]][rayon] | [![cat-concurrency-badge]][cat-concurrency] | | Test in parallel if any or all elements of a collection match a given predicate | [![rayon-badge]][rayon] | [![cat-concurrency-badge]][cat-concurrency] | | Search items using given predicate in parallel | [![rayon-badge]][rayon] | [![cat-concurrency-badge]][cat...
The Rust Cookbook Book 2024-01-01 ~1 min read
doc.rust-lang.org
...is a slice to the original string, hence no new // allocation is performed let chars_to_trim: &[char] = &[' ', ',']; let trimmed_str: &str = string.trim_matches(chars_to_trim); println!("Used characters: {}", trimmed_str); // Heap allocate a string let alice = String::from("I like dogs"); // Allocate new memory and store the...
Rust by Example Book 2024-01-01 ~4 min read
rustc-dev-guide.rust-lang.org
...Destruction scopes are also made explicit. • Statements, expressions, match arms, blocks, and parameters are stored separately. For example, statements in the stmts array reference expressions by their index (represented as a ExprId) in the exprs array. The THIR lives in rustc_mir_build::thir. To construct a thir::Expr, you...
Guide to Rustc Development Book 2024-01-01 ~4 min read
whileydave.com
...usize = __nondet(); // Apply Constraints __VERIFIER_assume(len <= LIMIT); __VERIFIER_assume(i < len); __VERIFIER_assume(xs[i] == x); // Compute result let result = index_of(&xs[..len],x); // Check it matches assert!(xs[result] == x); } This is roughly similar to before, except we now require some i where xs[i] == x. Also...
Observations/Thoughts 2021-10-27 ~6 min read
doc.rust-lang.org
...Code that looked like this: // Rust 2015 extern crate futures; use futures::Future; mod foo { pub struct Bar; } use foo::Bar; fn my_poll() -> futures::Poll { ... } enum SomeEnum { V1(usize), V2(String), } fn func() { let five = std::sync::Arc::new(5); use SomeEnum::*; match ... { V1(i) => { ... } V2(s) => { ... } } } will look...
The Rust Edition Guide Book 2024-01-01 ~7 min read
gekkio.fi
...let op = read_op(); match op { // ... 0xC1 => { // POP BC cpu.bc = mem_read_u16(cpu.sp); cpu.sp += 2; cpu.cycles += 3; }, 0xC5 => { // PUSH BC cpu.sp -= 2; mem_write_u16(cpu.sp, cpu.bc); cpu.cycles += 4; } // ... } This might seem perfectly fine, but is actually inaccurate if we look...
Blog Posts 2015-01-19 ~4 min read
www.shuttle.rs
...We want to check the row with that username has a password that matches. If the credentials match then we create a new session: Then we refer back to the signup section and replicate the same HTML form and handler that renders the Tera template as seen before but for...
Observations/Thoughts 2022-08-31 ~12 min read
"\#rustlang is a very strange place sans null deref nor data race it has its own styles but once it compiles it will not blow up in your face"

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.