mobiarch.wordpress.com
...fn make_dir(path: &str) -> std::io::Result<()> {
let err = match std::fs::create_dir(path) {
Ok(_) => return Ok(()),
Err(e) => e
};
match err.kind() {
ErrorKind::AlreadyExists => return Ok(()),
_ => {
println!("Failed to create directory: {}", path);
return Err(err);
}
};
}
getenv
Use std::env:var.
if let Ok(val) = std::env::var...
From the Blogosphere
2015-07-13
~2 min read
kerkour.com
...fn do_something() -> Result<(), Error> {
let user = get_user_opt().ok_or(Error::UserNotFound)?;
// do something
}
match
Then, of course, there is match:
fn do_something() -> Result<(), Error> {
let user = match get_user_opt() {
Some(user) => user,
None => return Err(Error::UserNotFound);
};
// do something
}
if let / let else
Even better...
Observations/Thoughts
2026-10-21
~7 min read
hirrolot.github.io
...for S<Lhs> is the induction step
(recursion case) – similar to how we did with pattern matching using
match. Likewise, as in the first example, the induction
works by reducing the first argument to Z:
<Lhs as Add<Rhs>>::Result works just like
add(next, rhs) – it invokes pattern matching...
Observations/Thoughts
2022-01-26
~30 min read
rust-lang-nursery.github.io
...badge]][cat-text-processing] | | Extract phone numbers from text | [![regex-badge]][regex] | [![cat-text-processing-badge]][cat-text-processing] | | Filter a log file by matching multiple regular expressions | [![regex-badge]][regex] | [![cat-text-processing-badge]][cat-text-processing] | Replace all occurrences of one text pattern with another pattern. | [![regex-badge...
The Rust Cookbook
Book
2024-01-01
~1 min read
docs.rs
...extern crate unicode_normalization_alignments; use unicode_normalization_alignments::char::compose; use unicode_normalization_alignments::UnicodeNormalization; fn main() { assert_eq!(compose('A','\u{30a}'), Some('Å')); let s = "ÅΩ"; let c = s.nfc().map(|(c, diff)| { match diff { 0 => println!("Nothing changed here"), 1 => println!("New character"), _ => println!("{} characters were...
Crate
v0.1.12
2019-12-30
crates.io
...Currently a lot of documentation is rather terse, referring to the matching methods on the string types in the standard library is best in those cases. Feel free to contribute more exhaustive in-line docs.
Crate
v0.2.0
2020-10-10
felix-knorr.net
...So I needed to transform my handler
functions so that their return type matches. In Python I would've used a
decorator function for that:
def eat_error(f):
def inner(*args, **kwargs):
return some_transformation(f(*args, **kwargs))
return inner
And I knew that there was this one type...
Rust Walkthroughs
2022-10-19
~6 min read
www.rustydonkey.dev
...All the same numeric comparisons are supported here too!
Text Matching: This one is really cool! You can find text that:
is exactly a certain string
starts with a substring
ends with a substring
contains a substring
Hierarchy: You can now also filter directly by an item's class and...
Project/Tooling Updates
2025-10-29
~4 min read
arzg.github.io
...Let’s add a todo!() and comment out the rest so we can get on with running our tests:impl Expr {
// snip
pub(crate) fn eval(&self, env: &Env) -> Result<Val, String> {
match self {
Self::Number(Number(n)) => Ok(Val::Number(*n)),
Self::Operation { lhs, rhs, op } => {
todo!();
// let Number...
Learn More Rust
2020-10-14
~25 min read
adventures.michaelfbryan.com
...std::slice::Iter<'src, Operation>,
}
Turning TextObjectParser into an Iterator turned out to be pretty easy
thanks to pattern matching. I know ahead of time exactly which operations
I’m looking for and what their operands will be so each pattern can be its
own branch in a big match...
Rust Walkthroughs
2021-02-03
~13 min read
minikin.me
...Presence<T>) {
match update {
Presence::Absent => {}, // Field missing from JSON → no change
Presence::Null => *target = None, // Field is null in JSON → clear
Presence::Some(v) => *target = Some(v), // Field has value → set it
}
}
fn apply_patch(user: &mut User, patch: UserPatch) {
apply_field(&mut user.name, patch.name);
apply_field...
Rust Walkthroughs
2025-12-17
~7 min read
blog.jetbrains.com
...When the output is not what you expected, it can be hard to see how the input matches the macro definition and what code the macro produced.
The new interactive declarative macro tester shows you the code your macro input expands into, as well as how the input and output...
Project/Tooling Updates
2026-07-22
~4 min read
docs.rs
...Example match rexif::parse_file(&file_name) { Ok(exif) => { println!("{} {} exif entries: {}", file_name, exif.mime, exif.entries.len()); for entry in &exif.entries { println!(" {}: {}", entry.tag, entry.value_more_readable); } }, Err(e) => { eprintln!("Error in {}: {} {}", &file_name, Error::description(&e), e.extra).unwrap(); } } The src/main.rs file is...
Crate
v0.7.6
2026-10-13
docs.rs
...ChannelBuilderError> { Ok(Channel { id: match self.id { Some(ref value) => Clone::clone(value), None => { return Err( Into::into( ::derive_builder::UninitializedFieldError::from("id"), ), ) } }, token: match self.token { Some(ref value) => Clone::clone(value), None => { return Err( Into::into( ::derive_builder::UninitializedFieldError::from("token"), ), ) } }, special_info: match self.special_info { Some...
Crate
v0.20.2
2024-10-08
arXiv
arxiv.org
...This work investigates aforementioned features, in particular pattern matching, providing a consistent view on how to apply MC/DC to Rust. Hence, this paper informs the implementation of Rust MC/DC tools, paving the road towards Rust in high-assurance applications.
Software Engineering
Wanja Zaeske, Pietro Albini, Florian Gilcher et al.
2024-09-13
arXiv:2409.08708
dev.to
...diesel::result::Error, context: &str) -> AppError {
AppError::new(
format!("{}: {}", context, err.to_string()).as_str(),
match err {
diesel::result::Error::DatabaseError(db_err, _) => {
match db_err {
diesel::result::DatabaseErrorKind::UniqueViolation => ErrorType::BadRequest,
_ => ErrorType::Internal,
}
}
diesel::result::Error::NotFound => ErrorType::NotFound,
// Here we can handle other cases if needed
_ => {
ErrorType::Internal...
Learn More Rust
2020-08-04
~20 min read
matthewkmayer.github.io
...database_instance_name.to_string(),
db_instance_class: "db.t2.micro".to_string(),
// name and login details should match `.env` in rusoto-rocket
master_user_password: Some("TotallySecurePassword501".to_string()),
master_username: Some("masteruser".to_string()),
db_name: Some("rusotodb".to_string()),
engine: "postgres".to_string(),
multi_az: Some(false...
News & Blog Posts
2017-05-23
~9 min read