pliniker.github.io
...Behold and scorn!
// loop state variables
let mut first_token = true;
let mut after_dot = false;
let mut expect_closeparen = false;
let mut expect_list = true;
loop {
match token {
// Open parenthesis
Some(Token { token: OpenParen, pos }) => {
if expect_closeparen {
return Err(ParseError::new(
pos, String::from("expected close-paren")));
}
if...
News & Blog Posts
2017-03-14
~4 min read
doc.rust-lang.org
...In “The match Control Flow Construct” section in Chapter 6, we discussed that match arms must all return the same type. So, for example, the following code doesn’t work:
The type of guess in this code would have to be an integer and a string, and Rust requires that...
The Rust Programming Language
Book
2024-02-01
~9 min read
pretired.dazwilkin.com
...do-apps-rust 2020-10-08T18:47:56.540626070Z => Matched: GET / (default)
do-apps-rust 2020-10-08T18:47:56.540663254Z => Outcome: Success
do-apps-rust 2020-10-08T18:47:56.543531368Z => Response succeeded.
do-apps-rust 2020-10-08T18:47:56.903673975Z GET /favicon.ico image/avif:
do-apps...
Learn More Rust
2020-10-14
~5 min read
hermanradtke.com
...I found it easiest to use the match keyword when working with these types. There are also combinator functions like map and and_then which allow a set of computations to be chained together. I like to chain combinators together so error logic is separated from the main logic of...
News & Blog Posts
2016-09-20
~11 min read
blog.servo.org
...mattnenterprise updated some older Fetch code to match changes to the specification.
beholdnec fixed a shader problem that was breaking Servo on some AMD drivers.
karenher added support for tracking line numbers in the HTML parser.
canaltinova corrected the serialization of overflow properties in CSS.
hiikezoe made animated colors use...
Other Weeklies from Rust Community
2017-01-10
~2 min read
gliderkite.github.io
...use std::env;
let dataset = match env::args().nth(1) {
Some(path) => path,
_ => panic!("The path of the census file must be specified"),
};
As a final note, the underscore _ you see in the above match is an identifier
that can be used to match anything else (i.e. any other...
Learn Simple Rust
2020-10-21
~30 min read
arzg.github.io
...Open up expr.rs and scroll down to that todo!() we added earlier:impl Expr {
pub(crate) fn eval(&self) -> Val {
match self {
Self::Number(Number(n)) => Val::Number(*n),
Self::Operation { lhs, rhs, op } => {
let Number(lhs) = lhs;
let Number(rhs) = rhs;
let result = match op {
Op::Add => lhs...
Learn More Rust
2020-10-07
~27 min read
rust-analyzer.github.io
...14004 don’t escape non-snippets in Move const to impl.
#14011 fix Unwrap block for let statements.
#14037 handle boolean scrutinees better in Match to if-let assist.
#14039 make Add missing impl members work for impls inside blocks.
#14038 don’t fail workspace loading if sysroot can’t...
Project/Tooling Updates
2023-02-01
~1 min read
hermanradtke.com
...loop {
match self.sock.try_read_buf(&mut recv_buf) {
// the socket receive buffer is empty, so let's move on
// try_read_buf internally handles WouldBLock here too
Ok(None) => {
debug!("CONN : we read 0 bytes");
break;
},
Ok(Some(n)) => {
debug!("CONN : we read {} bytes", n);
// if we read...
From the Blogosphere
2015-07-27
~7 min read
www.nahua.dev
...TokenStream = match &self.col_type {
ColumnType::Char(_)
...
ColumnType::Float(_) => "f32".to_owned(),
ColumnType::Double(_) => "f64".to_owned(),
ColumnType::Json | ColumnType::JsonBinary => "Json".to_owned(),
ColumnType::Date => match date_time_crate {
DateTimeCrate::Chrono => "Date".to_owned(),
DateTimeCrate::Time => "TimeDate".to_owned(),
},
ColumnType::Time(_) => match date_time_crate {
DateTimeCrate::Chrono => "Time".to...
Rust Walkthroughs
2022-06-29
~17 min read
mainmatter.com
...PdfWriterConfiguration) -> Result<Term, RustlerError> {
match priv_create_pdf(config) {
Ok(()) => Ok(atoms::ok().to_term(env)),
Err(ref error) => return Err(RustlerError::Term(Box::new(io_error_to_term(error)))),
}
}
fn priv_create_pdf(config: PdfWriterConfiguration) -> Result<(), std::io::Error> {}create_pdf is slightly more complicated as it involves some...
Rust Walkthroughs
2023-02-08
~8 min read
rtoch.com
...LinkedList<Vec<Operation>> = LinkedList::new();
stack.push_back(Vec::new());
for token in tokens {
let cur_operations = stack.back_mut().expect("Stack should not be empty!");
match token {
Token::MoveRight => {
if let Some(Operation::MoveRight(x)) = cur_operations.last_mut() {
*x += 1;
} else {
cur_operations.push(Operation::MoveRight(1))
}
}
Token...
Miscellaneous
2022-03-23
~7 min read
smista.ai
...MemoryArgs) -> Result<String, Self::Error> {
let MemoryArgs {
op,
scope,
key,
value,
} = args;
match op {
MemoryOp::Record => {
let value = value.ok_or(MemoryToolError::MissingValue)?;
match scope {
MemoryScope::User => {
self.storage
.put_user_memory(Some(key.clone()), value)
.await?;
}
MemoryScope::Session => {
self.storage
.put_session_memory(Some(key.clone()), value)
.await?;
}
}
Ok...
Rust Walkthroughs
2026-06-17
~7 min read
doc.rust-lang.org
...algebraic data types, pattern matching, type inference, semicolon statement separation
• C++: references, RAII, smart pointers, move semantics, monomorphization, memory model
• ML Kit, Cyclone: region based memory management
• Haskell (GHC): typeclasses, type families
• Newsqueak, Alef, Limbo: channels, concurrency
• Erlang: message passing, thread failure, ,
• Swift: optional bindings
• Scheme: hygienic macros
• C#: attributes...
The Rust Reference
Book
2024-01-01
~1 min read
jackh726.github.io
...fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) {
((u,),) => u,
}
}
fn main() {
let y = Box::new((42,));
let x = transmute_lifetime(&y);
}
Stable emits the following error:
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> src/main.rs:2:11
|
2 | match...
Observations/Thoughts
2022-06-15
~13 min read
github.com
...In the MIR, all drops are explicit, including those that result from
panics and unwinding.
- **How matches are desugared.** Reasoning about matches has been a
traditional source of complexity. Matches combine traversing types
with borrows, moves, and all sorts of other things, depending on the
precise patterns in use. This...
RFC 1211
RFC
2015-07-14
~27 min read
integer32.com
...usize) -> Result<&str> {
let s = &s[location..];
match s.find("\n") {
Some(pos) => {
let head = &s[..pos];
Ok((head, location + pos + "\n".len()))
},
None => {
Err(location)
}
}
}
fn main() {
let input = "hello\nworld";
assert_eq!(Ok(("hello", 6)), parse_until_newline(input, 0));
assert_eq!(Err(6), parse_until_newline(input...
News & Blog Posts
2017-02-07
~5 min read
rust-lang.github.io
...Attribute
invocations can only match the attr rules, and non-attribute invocations can
only match the non-attr rules. This allows adding attr rules to an existing
macro without breaking backwards compatibility.
An attribute macro may emit code containing another attribute, including one
provided by an attribute macro. An attribute...
Compiler
2025-08-13
~7 min read
rust.code-maven.com
...let database_folder = match std::env::var("DATABASE_PATH") {
Ok(val) => std::path::PathBuf::from(val),
Err(_) => {
let current_dir = std::env::current_dir().unwrap();
current_dir.join("db")
}
};
Connect to the database on the filesystem
Then we connect to the database folder via the RocksDb driver.
let db = Surreal...
Miscellaneous
2024-01-17
~5 min read
info.varnish-software.com
...Let's have a look at that match statement again. I told you it had some nice features, but didn't go too deep about them. One very cool aspect is destructuring, that we'll use. Match is able to give you direct access to element of a struct or...
News & Blog Posts
2016-04-11
~11 min read