rust-lang.github.io
...rust-lang/rust#51994
Summary
Tuple structs can now be constructed and pattern matched with
Self(v1, v2, ..). A simple example:
struct TheAnswer(usize);
impl Default for TheAnswer {
fn default() -> Self { Self(42) }
}
Similarly, unit structs can also be constructed and pattern matched with Self.
Motivation
This RFC proposes a...
Updates from Rust Core
2018-09-18
~6 min read
crates.io
...In order for the filter to match, it is enough that one rule associated to the system call matches. A system call may also map to an empty rule vector, which means that the system call will match, regardless of the actual arguments. The following diagram models a simple filter...
Crate
v0.5.0
2025-03-07
doc.rust-lang.org
fn eq_ignore_ascii_case(&self, other: &Self) -> bool
AsciiExt::eq_ignore_ascii_case — Checks that two values are an ASCII case-insensitive match.
Same as to_ascii_lowercase(a) == to_ascii_lowercase(b), but without allocating and copying temporaries.
Note
This method is deprecated in favor of the identically-named inherent methods on u8, char, [u8] and str.
method
std
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub fn shrink_to_fit(&mut self)
OsString::shrink_to_fit — Shrinks the capacity of the OsString to match its length.
See the main OsString documentation information about encoding and capacity units.
Examples
use std::ffi::OsString;
let mut s = OsString::from("foo");
s.reserve(100);
assert!(s.capacity() >= 100);
s.shrink_to_fit();
assert_eq!(3...
method
std
Stable since 1.19.0
Version 1.100.0-nightly
docs.rs
...Examples From a file match imagesize::size("example.webp") { Ok(size) => println!("Image dimensions: {}x{}", size.width, size.height), Err(why) => println!("Error getting dimensions: {:?}", why) } From a vector let data = vec![0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x64, 0x00, 0x64, 0x00]; match imagesize::blob_size(&data) { Ok(size) => println...
Crate
v0.15.0
2026-07-09
github.com
...BytesMut = "*2\r\n+Foo\r\n+Bar\r\n".into(); let total_len = bytes.len(); let (frame, amt, buf) = match decode_bytes_mut(&mut bytes) { Ok(Some(result)) => result, Ok(None) => panic!("Expected complete frame"), Err(e) => panic!("{:?}", e) }; assert_eq!(frame, expected.0, "decoded frame matched"); assert_eq...
Crate
v6.0.0
2024-11-15
rust-analyzer.github.io
...layer.
#10689 handle pub tuple fields in tuple structs.
#10720 don’t ascribe types in pattern completion for param patterns twice.
#10747 remove faulty logic for ascending test attributes for runnables.
#10762 trigger flyimport on enum variants.
#10759 make add_missing_match_arms applicable at the end of the match.
Project/Tooling Updates
2021-11-17
~1 min read
doc.rust-lang.org
pub struct SplitMut<'a, T, P>
SplitMut — An iterator over the mutable subslices of the vector which are separated by elements that match pred.
This struct is created by the split_mut method on slices.
Example
let mut v = [10, 40, 30, 20, 60, 50];
let iter = v.split_mut(|num| *num % 3 == 0);
struct
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub macro try!
...fn write_to_file_using_match() -> Result<(), MyError> {
let mut file = r#try!(File::create("my_best_friends.txt"));
match file.write_all(b"This is a list of my best friends.") {
Ok(v) => v,
Err(e) => return Err(From::from(e)),
}
Ok(())
}
macro
core
Stable since 1.0.0
Version 1.100.0-nightly
hassamuddin.com
...Packet
) {
match packet {
Packet::Pingreq => {
println!("Ping");
framed.send(Packet::Pingresp).await;
}
_ => {
// now what?
}
}
}
pub async fn handle_client(
stream: TcpStream,
addr: SocketAddr
) {
let mut framed = Framed::new(stream, MQTTCodec::new());
// do connection handshake
let connect = match framed.next().await {
Some(Ok(Packet::Connect(packet))) => {
framed.send(Packet::Connack( Connack...
Learn More Rust
2020-09-04
~7 min read
blog.cloudflare.com
...It’s built using our engine, Wirefilter, which takes powerful boolean expressions written by customers and matches incoming requests against them. Customers can then choose how to respond to traffic which matches these rules. We will discuss some in-depth optimizations we have recently made to Wirefilter, so you may...
Miscellaneous
2020-09-30
~11 min read
tech.marksblogg.com
...fn main() {
let matches = command!()
.arg(arg!(--function <VALUE>).required(true))
.get_matches();
let function = matches.get_one::<String>("function").expect("required");
loop {
let mut input = String::new();
match io::stdin().read_line(&mut input) {
Ok(n) => {
if n == 0 {
// End files
break;
}
let mut result = match function.as_str...
Rust Walkthroughs
2023-09-20
~4 min read
doc.rust-lang.org
...Within $() is $x:expr, which matches any Rust expression and gives the expression the name $x.
The comma following $() indicates that a literal comma separator character must appear between each instance of the code that matches the code in $(). The * specifies that the pattern matches zero or more of whatever...
The Rust Programming Language
Book
2024-02-01
~17 min read
github.com
## Summary
[summary]: #summary
Tuple `struct`s can now be constructed and pattern matched with
`Self(v1, v2, ..)`. A simple example:
```rust
struct TheAnswer(usize);
impl Default for TheAnswer {
fn default() -> Self { Self(42) }
}
```
Similarly, unit structs can also be constructed and pattern matched with `Self`.
## Motivation
[motivation]: #motivation
This RFC...
RFC 2302
RFC
2017-01-18
~7 min read
tweedegolf.nl
...messageBytes, message_type } = received;
assert.strictEqual(sender, alice_identifier, "Sender does not match Alice's identifier");
let receivedMessage = String.fromCharCode.apply(null, messageBytes);
assert.strictEqual(receivedMessage, message, "Received message does not match");
assert.strictEqual(message_type, MessageType.SignedAndEncrypted, "Message type does not match SignedAndEncrypted");
} else {
assert.fail(`Unexpected message type...
Rust Walkthroughs
2024-10-02
~7 min read
doc.rust-lang.org
pub struct Split<'a, T, P>
Split — An iterator over subslices separated by elements that match a predicate function.
This struct is created by the split method on slices.
Example
let slice = [10, 40, 33, 20];
let mut iter = slice.split(|num| num % 3 == 0);
assert_eq!(iter.next(), Some(&[10, 40][..]));
assert_eq!(iter.next...
struct
core
Stable since 1.0.0
Version 1.100.0-nightly
ohadravid.github.io
...since the TypeScript document has tokens matching both terms, we will consider it a match for this query.
We can let the user specify that they want a more “exact” match, for example by using "javascript language", meaning that the term language must follow the term javascript.Our index currently...
Observations/Thoughts
2025-04-16
~17 min read
matklad.github.io
...u32) -> Option<Error> {
let res = match code {
0 => Error::InvalidSignature,
1 => Error::AccountNotFound,
2 => Error::InsufficientBalance,
_ => return None,
};
Some(res)
}
}
Now, given that I expect this type to change frequently, this is
asking for trouble! It’s very easy for the match and
the enum definition to get out of...
Observations/Thoughts
2022-03-30
~10 min read
doc.rust-lang.org
pub fn split<P>(&self, pat: P) -> Split<'_, P>
str::split — Returns an iterator over substrings of this string slice, separated by characters matched by a pattern.
The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.
If there are no matches the full string slice is...
method
core
Stable since 1.0.0
Version 1.100.0-nightly
doc.rust-lang.org
pub struct SplitNMut<'a, T, P>
SplitNMut — An iterator over subslices separated by elements that match a predicate function, limited to a given number of splits.
This struct is created by the splitn_mut method on slices.
Example
let mut slice = [10, 40, 30, 20, 60, 50];
let iter = slice.splitn_mut(2, |num| *num % 3...
struct
core
Stable since 1.0.0
Version 1.100.0-nightly