pietro.menna.net.br
...PeerMessage) -> Result<(), Error> {
match message {
PeerMessage::CancelRequest(piece_index, block_index) => {
match self.requests_in_progress.iter().position(|r| r.matches(piece_index, block_index)) {
Some(i) => {
let r = self.requests_in_progress.remove(i);
self.send_message(Message::Cancel(r.piece_index, r.offset, r.block_length))
},
None => Ok...
From the Blogosphere
2015-06-22
~7 min read
ibraheem.ca
...Like a match statement, but for I/O operations.
loop {
// If only...
match {
ctrl_c() => {
break;
},
Ok((connection, _)) = listener.accept() => {
std::thread::spawn(|| ...);
}
}
}
And what about timing out long running requests after thirty seconds? We could set a flag that tells threads to stop, but how often would they check...
Observations/Thoughts
2023-08-16
~88 min read
crates.io
...This allows us to write custom preconditions for matching code. Let's make this more clear with a concrete example. Here is the declaration of an external extractor to match on the high-level instruction that defined a given operand Value , along with a new rule to sink loads into...
Crate
v0.123.14
2026-08-20
doc.rust-lang.org
pub fn unbound() -> io::Result<UnixDatagram>
UnixDatagram::unbound — Creates a Unix Datagram socket which is not bound to any address.
Examples
use std::os::unix::net::UnixDatagram;
let sock = match UnixDatagram::unbound() {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't unbound: {e:?}");
return
}
};
associated_function
std
Stable since 1.10.0
Version 1.100.0-nightly
aturon.github.io
...DomString) -> AttrValue {
match name {
&atom!("id") => AttrValue::from_atomic(value),
&atom!("class") => AttrValue::from_serialized_tokenlist(value),
_ => default::parse_plain_attribute(self, name, value),
}
}
}
impl ParsePlainAttribute for HtmlAnchorElement {
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
match name {
&atom!("rel") => AttrValue::from_serialized_tokenlist(value),
_ => default::parse_plain...
News & Blog Posts
2015-09-21
~24 min read
doc.rust-lang.org
pub fn bind<P>(path: P) -> io::Result<UnixListener>
UnixListener::bind — Creates a new UnixListener bound to the specified socket.
Examples
use std::os::unix::net::UnixListener;
let listener = match UnixListener::bind("/path/to/the/socket") {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't connect: {e:?}");
return
}
};
associated_function
std
Stable since 1.10.0
Version 1.100.0-nightly
rust-analyzer.github.io
...trying to use an uncached syntax node in Semantics.
#10460 only add proc_macro to prelude in proc-macro crates.
#10477 fix parsing of macro call inside generic args.
#10449 fix parsing of Some(1..).
#10420 parse outer attributes on StructPatternEtCetera.
#10480 change snake case fix to match rustc implementation.
Project/Tooling Updates
2021-10-13
~1 min read
docs.rs
...cannot move out of borrowed content *self = match *self { // ^^^^^ cannot move out of borrowed content States::A(a) => States::B(a), States::B(a) => States::A(a), }; } } Depending on context this can be quite tricky to work around. With this crate, however: enum States { A(String), B(String), } impl States...
Crate
v0.1.8
2025-05-20
www.snoyman.com
...f64,
}
#[derive(Clone, Copy)]
enum State {
Arizona,
Nevada,
Utah,
}
impl State {
fn tax_rate(self) -> f64 {
match self {
State::Arizona => 0.05,
State::Nevada => 0.08,
State::Utah => 0.09,
}
}
}
#[derive(Clone, Copy)]
enum Item {
Apples,
Eggs,
}
impl Item {
fn price(self) -> f64 {
match self {
Item::Apples => 0.5,
Item...
Rust Walkthroughs
2024-08-28
~10 min read
crates.io
...Linux, Windows, MacOS, FreeBSD, OpenBSD, illumos Example use mac_address::get_mac_address; fn main() { match get_mac_address() { Ok(Some(ma)) => { println!("MAC addr = {}", ma); println!("bytes = {:?}", ma.bytes()); } Ok(None) => println!("No MAC address found."), Err(e) => println!("{:?}", e), } } License mac_address is licensed under both MIT and...
Crate
v1.1.8
2025-02-10
doc.rust-lang.org
pub fn bind<P>(path: P) -> io::Result<UnixDatagram>
UnixDatagram::bind — Creates a Unix datagram socket bound to the given path.
Examples
use std::os::unix::net::UnixDatagram;
let sock = match UnixDatagram::bind("/path/to/the/socket") {
Ok(sock) => sock,
Err(e) => {
println!("Couldn't bind: {e:?}");
return
}
};
associated_function
std
Stable since 1.10.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn pair() -> io::Result<(UnixDatagram, UnixDatagram)>
UnixDatagram::pair — Creates an unnamed pair of connected sockets.
Returns two UnixDatagramss which are connected to each other.
Examples
use std::os::unix::net::UnixDatagram;
let (sock1, sock2) = match UnixDatagram::pair() {
Ok((sock1, sock2)) => (sock1, sock2),
Err(e) => {
println!("Couldn't unbound: {e:?}");
return
}
};
associated_function
std
Stable since 1.10.0
Version 1.100.0-nightly
matthewkmayer.github.io
...fn make_org_url(matches: &clap::ArgMatches) -> String {
let org = matches
.value_of("ORG")
.expect("Please specify a github org");
if !org_is_just_org(&org) {
match suggest_org_arg(&org) {
Ok(suggestion) => panic!("Try this for the org value: {}", suggestion),
Err(_) => panic!("Please make org just the organization name...
News & Blog Posts
2017-10-24
~6 min read
www.fpcomplete.com
...So let's rewrite this without any early return, and instead use some pattern matching:
fn age() -> Option<i32> {
match (birth_year(), current_year()) {
(Some(birth_year), Some(current_year)) => Some(current_year - birth_year),
_ => None,
}
}
This certainly works, but it's verbose. It also doesn't generalize to other...
Observations/Thoughts
2020-12-09
~22 min read
dystroy.org
...Result<T, E>) -> T {
match res {
Ok(v) => v,
Err(e) => {
log::error!("Fatal error: {}", e);
Timer::after_millis(100).await;
panic!("Fatal error: {}", e);
}
}
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_rp::init(Default::default());
// Logger USB — must be before everything else
let usb_driver...
Rust Walkthroughs
2026-06-17
~50 min read
rust-analyzer.github.io
#12382 make auto-closing angle brackets configurable, disabled by default.
#12341 make files.excludeDirs work.
#12355 fix inference when pattern matching a tuple field with a wildcard.
#12409 fix overflow during type inference for tuple struct patterns.
#12384, #12386 Generate variant: insert code in file with enum definition.
#12370 insert...
Project/Tooling Updates
2022-06-01
~1 min read
neosmart.net
...ignore-result for rust Safely ignore errors in function return values when the result isn't critical This crate adds a .ignore() function to Result instances that ignores both the Ok and Err variants of the result, silencing compiler warnings about unused errors without needing to resort to empty match...
Crate
v0.2.0
2018-12-24
github.com
...The effect will be to convert uses of arrays such as this:
```rust
let a: [uint, ..2] = [0u, ..2];
```
to this:
```rust
let a: [uint; 2] = [0u; 2];
```
### Match patterns
In match patterns, `..` is always interpreted as a wildcard for constructor
arguments (or for slice patterns under the `advanced_slice...
RFC 520
RFC
2014-12-13
~5 min read
www.worthe-it.co.za
...It
follows that the lifetime of variables used inside the new thread must
match those of the new thread, not the function that it was spawned
from.use std::thread;
let outside_value = String::from("Hello world");
let child_thread = thread::spawn(move || {
// this new thread may outlive the context...
News & Blog Posts
2017-07-18
~10 min read
jtjlehi.github.io
...let (removes, inserts): (Vec<_>, Vec<_>) = updates
.into_iter()
// we have to make sure that removes happen at the correct offset
.scan(0, |num_inserts, update| {
Some(match update {
Update::Remove(idx) => Update::Remove(idx + *num_inserts),
insert @ Update::Insert(_, _) => {
*num_inserts += 1;
insert
}
})
})
.partition(|updates| matches!(updates, Update::Remove(_)))
To...
Rust Walkthroughs
2025-03-26
~14 min read