docs.rs
...use tokio::time::{Duration, sleep}; #[tokio::main] async fn main() { let (tx, mut rx) = bmrng::channel_with_timeout::<i32, i32>(100, Duration::from_millis(100)); tokio::spawn(async move { match rx.recv().await { Ok((input, mut responder)) => { sleep(Duration::from_millis(200)).await; let res = responder.respond(input * input); assert...
Crate
v0.5.2
2021-08-24
slawlor.github.io
...Self::Msg, _state: &mut Self::State)
-> Result<(), ActorProcessingErr>
{
match message {
MyFirstActorMessage::PrintHelloWorld => {
println!("Hello world!");
}
}
Ok(())
}
}
Ok now that looks better! Here we’ve added the message handler handle() method which will be executed for every message received in
the queue.
All together nowPermalink
Let’s wire it all up...
Project/Tooling Updates
2024-11-06
~5 min read
encore.dev
...When the bytes match, our server is answering the way the reference implementation does.
Running the reference suite this way surfaced differences that would be easy to miss otherwise. One of them was in how expiry is tested, where the suite advances a mock clock to check that keys expire...
Observations/Thoughts
2026-07-01
~5 min read
blog.shortepic.com
...impl Display for Square {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let s = match self {
Square::Empty => "",
Square::X => "X",
Square::O => "O",
};
write!(f, "{}", s)
}
}
impl Display for Status {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let s = match self {
Status::Playing => "Next player: ",
Status::Won => "Winner: ",
};
write!(f...
Learn More Rust
2020-10-07
~5 min read
diziet.dreamwidth.org
...Parseable + Default {
match self.end {
Ok(match self.end {
LinkEnd::Client => self.ordinary(key, skl)?,
LinkEnd::Client => self.ordinary(key, skl)?,
LinkEnd::Server => default(),
LinkEnd::Server => default(),
}
})
…
…
Return value and Ok(()) entirely replaced by #[throws]:
impl Display for Loc {
impl Display for Loc {
#[throws(fmt::Error)]
fn fmt(&self, f...
Observations/Thoughts
2022-12-21
~13 min read
rust-lang-nursery.github.io
...badge]][csv] | [![cat-encoding-badge]][cat-encoding] | | Read CSV records with different delimiter | [![csv-badge]][csv] | [![cat-encoding-badge]][cat-encoding] | | Filter CSV records matching a predicate | [![csv-badge]][csv] | [![cat-encoding-badge]][cat-encoding] | | Handle invalid CSV data with Serde | [![csv-badge]][csv] [![serde-badge]][serde] | [![cat-encoding-badge...
The Rust Cookbook
Book
2024-01-01
~1 min read
doc.rust-lang.org
...If next returns Some, we use a match to extract the value. If it returns None, it means not enough arguments were given, and we return early with an Err value. We do the same thing for the file_path value.
Clarifying Code with Iterator Adapters
We can also take...
The Rust Programming Language
Book
2024-02-01
~5 min read
christian.amsuess.com
...W) -> Result<(), W::Error> {
let chunk = self.data.view(request_data.block);
match chunk {
Ok((payload, option)) => {
message.set_code(code::Content);
message.add_opaque_option(option::ETag, &self.etag)?;
message.add_block_option(option::Block2, option);
message.add_payload(payload)?;
}
Err(_) => {
message.set_code(code::BadRequest);
}
};
Ok(())
}
As these...
Call for Blog Posts
2020-09-30
~5 min read
stace.dev
...if let Some(answer) = get_answer(&response) {
match answer {
DnsRecord {
data: DnsRecordData::Ipv4Addr(ip),
type_: TYPE_A,
..
} => return Ok(*ip),
DnsRecord {
data: DnsRecordData::Name(name),
type_: TYPE_CNAME,
..
} => return resolve(name, TYPE_A),
_ => {
panic!("resolve: something went wrong")
}
}
}
Using match to destructure the data enum based on a DNS record...
Observations/Thoughts
2023-07-19
~5 min read
rust-lang-nursery.github.io
...The path! macro is used to define what URL matches. The :query is a template — it matches anything and stores the value as query for the component to read later.
<A> anchors links while <Routes fallback=...> is used to provide a default.
More in the Leptos book: Defining <Routes/> and...
The Rust Cookbook
Book
2024-01-01
~3 min read
blog.viraptor.info
...It
doesn’t support regex matching or casting parameters to the right type, but
it’s functional. Same goes for logging and static file handling. No thrills,
they work.
There aren’t that many template libraries to choose from yet, but
handlebars-iron does the job.
The feeling that when...
Notable Links
2015-06-07
~7 min read
docs.rs
...find_executable_in_path is the most convenient function exported by this crate; given the name of an executable, it will yield the absolute path of the first matching file. use pathsearch::find_executable_in_path; if let Some(exe) = find_executable_in_path("ls") { println!("Found ls at {}", exe...
Crate
v0.2.0
2020-04-11
doc.rust-lang.org
pub const UNIX_EPOCH: SystemTime
...Examples
use std::time::{SystemTime, UNIX_EPOCH};
match SystemTime::now().duration_since(UNIX_EPOCH) {
Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}
constant
std
Stable since 1.8.0
Version 1.100.0-nightly
www.evanmiller.org
...Like if, match is an expression, not a statement, so it can be used as an rvalue. But unlike if, match doesn’t suffer from the phantom-else problem. The compiler uses type-checking to guarantee that the match will match something — or speaking more precisely, the compiler will complain...
Notable Links
2015-05-18
~35 min read
crates.io
...std")] { let (response_sender, response_receiver) = oneshot::channel(); let request = Request::from("data from sync thread"); processor.send((request, response_sender)).expect("Processor down"); match response_receiver.recv_timeout(Duration::from_secs(1)) { // <- Receive on the oneshot channel Ok(result) => println!("Processor returned {}", result), Err(oneshot::RecvTimeoutError::Timeout) => eprintln!("Processor...
Crate
v0.2.1
2026-02-23
mtigley.dev
...action_status is an immutable referencee to the player object’s associated ActionStatus component, which we will use to match on its action_type property:match action_status.action_type {
Action::Idle => {
sprite.sprite_number = animation.first_sprite_index + frame as usize;
},
Action::Run => {
// The first running animation is the...
Learn More Rust
2020-08-26
~7 min read
doc.rust-lang.org
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>>
...Examples
use std::process::Command;
let mut child = Command::new("ls").spawn()?;
match child.try_wait() {
Ok(Some(status)) => println!("exited with: {status}"),
Ok(None) => {
println!("status not ready yet, let's really wait");
let res = child.wait();
println!("result: {res:?}");
}
Err(e) => println!("error attempting to wait: {e}"),
}
method
std
Stable since 1.18.0
Version 1.100.0-nightly
doc.rust-lang.org
const UNIX_EPOCH: SystemTime
...Examples
use std::time::SystemTime;
match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
}
associated_constant
std
Stable since 1.28.0
Version 1.100.0-nightly
flodl.dev
...Recurrent — full sequence modules, not just cells:
// Multi-layer GRU matching nn.GRU exactly
let gru = GRU::new(128, 256, 2)?; // 2 layers
let (output, h_n) = gru.forward_seq(&x, None)?;
// Multi-layer LSTM matching nn.LSTM
let lstm = LSTM::new(128, 256, 2)?;
let (output, (h_n, c...
Project/Tooling Updates
2026-04-01
~5 min read
doc.rust-lang.org
...Note that we do not perform coercions when matching traits (except for receivers, see the next page). If there is an impl for some type U and T coerces to U, that does not constitute an implementation for T. For example, the following will not type check, even though it...
The Rustonomicon
Book
2024-01-01
~1 min read