doc.rust-lang.org
pub const fn wrapping_shl(self, rhs: u32) -> Self
...Instead, the behaviour of this method matches what shift instructions do on many processors, and is what the << operator does when overflow checks are disabled, but numerically it's weird. Consider, instead, using Self::unbounded_shl which has nicer behaviour.
Note that this is not the same as a rotate...
method
core
Stable since 1.2.0
Version 1.100.0-nightly
doc.rust-lang.org
pub const fn wrapping_shr(self, rhs: u32) -> Self
...Instead, the behaviour of this method matches what shift instructions do on many processors, and is what the >> operator does when overflow checks are disabled, but numerically it's weird. Consider, instead, using Self::unbounded_shr which has nicer behaviour.
Note that this is not the same as a rotate...
method
core
Stable since 1.2.0
Version 1.100.0-nightly
docs.rs
...Cohen-Sutherland TODO Cyrus-Beck Liang-Barsky Nicholl-Lee-Nicholl More comprehensive testing Installation cargo add line-clipping Minimum supported Rust version The crate is built with Rust 1.85 to match the 2024 edition. The MSRV may increase in a future minor release, but will be noted in the...
Crate
v0.3.8
2026-08-03
doc.rust-lang.org
pub fn open<P>(&self, path: P) -> io::Result<File>
...The following errors don't match any existing io::ErrorKind at the moment:
• One of the directory components of the specified file path was not, in fact, a directory.
• Filesystem-level errors: full disk, write permission requested on a read-only file system, exceeded disk quota, too many open files...
method
std
Stable since 1.0.0
Version 1.100.0-nightly
kmcallister.github.io
...main() {
::std::io::stdio::println_args(
::std::fmt::Arguments::new({
#[inline]
#[allow(dead_code)]
static __STATIC_FMTSTR: &'static [&'static str]
= &["Hello, world!"];
__STATIC_FMTSTR
}, &match () { () => [], }));
}
Freeze the shape of the tree
Assign each node a unique NodeId
Build an index by NodeId of AST nodes and their parents
See libsyntax...
Blog Posts
2015-01-19
~6 min read
blog.digital-horror.com
...Think of this as a simple client-server connection.loop {
match socket.read(&mut buf).await {
Ok(0) => returing,
Ok(n) => {
println!(
"received {} bytes, msg: {}",
n,
String::from_utf8_lossy(buf.clone()[..n].to_vec().as_slice())
);
socket
.write_all(&buf[..n])
.await
.expect("failed to write data to socket...
Observations/Thoughts
2024-05-29
~6 min read
crates.io
...use btoi::btoi; assert_eq!(Ok(42), btoi(b"42")); assert_eq!(Ok(-1000), btoi(b"-1000")); Documentation Read the documentation MSRV policy The minimum supported Rust version is 1.60, matching num_traits , with no intent to ever increase it. That's because #![feature(int_from_ascii)] in the...
Crate
v0.5.0
2025-05-29
docs.rs
...Only emits a single Rename event if the rename From and To events can be matched Merges multiple Rename events Takes Rename events into account and updates paths for events that occurred before the rename event, but which haven't been emitted, yet Optionally keeps track of the file system...
Crate
v0.8.0
2026-11-21
doc.rust-lang.org
pub fn peek(&self, buf: &mut [u8]) -> io::Result<usize>
...Examples
use std::net::UdpSocket;
let socket = UdpSocket::bind("127.0.0.1:34254").expect("bind should succeed");
socket.connect("127.0.0.1:8080").expect("connect should succeed");
let mut buf = [0; 10];
match socket.peek(&mut buf) {
Ok(received) => println!("received {received} bytes"),
Err(e) => println!("peek function...
method
std
Stable since 1.18.0
Version 1.100.0-nightly
gill.net.in
...u16,
) -> Option<(Device<T>, DeviceHandle<T>)> {
let devices = match context.devices() {
Ok(d) => d,
Err(_) => return None,
};
for device in devices.iter() {
let device_desc = match device.device_descriptor() {
Ok(d) => d,
Err(_) => continue,
};
if device_desc.vendor_id() == vid && device_desc.product_id() == pid {
match device.open() {
Ok(handle...
Learn More Rust
2020-08-04
~14 min read
rust-lang-nursery.github.io
...guess_format reads the leading magic bytes and returns the matching ImageFormat, which in turn gives the MIME type through ImageFormat::to_mime_type. Only the header is examined, so a short prefix of the file is enough.
Inspect image EXIF metadata
[![kamadak-exif-badge]][kamadak-exif] [![cat-multimedia-badge...
The Rust Cookbook
Book
2024-01-01
~1 min read
crates.io
...Pin<&mut Self>) { match self.project() { EnumProj::Pinned(x) => { let _: Pin<&mut T> = x; } EnumProj::Unpinned(y) => { let _: &mut U = y; } } } } code like this will be generated See #[pin_project] attribute for more details, and see examples directory for more examples and generated code. Related Projects pin-project-lite : A...
Crate
v1.2.0
2026-11-19
crates.io
...for n in 0..100 { match circuit_breaker.call(|| dangerous_call()) { Err(Error::Inner(_)) => { eprintln!("{}: fail", n); }, Err(Error::Rejected) => { eprintln!("{}: rejected", n); break; }, _ => {} } } Or configure custom backoff and policy: use std::time::Duration; use failsafe::{backoff, failure_policy, CircuitBreaker}; // Create an exponential growth backoff which starts from 10s and...
Crate
v1.3.0
2024-07-05
doc.rust-lang.org
pub const fn cold_path()
...i32) -> i32 {
match x {
1 => 10,
2 => 100,
3 => { cold_path(); 1000 }, // this branch is unlikely
_ => { cold_path(); 10000 }, // this is also unlikely
}
}
This can also be used to implement likely and unlikely helpers to hint the condition rather than the branch:
use core::hint::cold_path;
#[inline(always)]
pub...
function
core
Stable since 1.95.0
Version 1.100.0-nightly
arXiv
arxiv.org
...While Rust is often claimed to match C's performance, runtime safety checks, compiler optimizations, and hardware microarchitecture interact in ways that complicate performance diagnosis. We first conduct a systematic cross-layer characterization of 12 benchmarks comprising C implementations and their Rust counterparts. Our study reveals that runtime safety checks...
Performance
Dalton Davis, Kunal Pai, Tapti Palit
2026-11-24
arXiv:2611.33490
doc.rust-lang.org
...is a slice to the original string, hence no new
// allocation is performed
let chars_to_trim: &[char] = &[' ', ','];
let trimmed_str: &str = string.trim_matches(chars_to_trim);
println!("Used characters: {}", trimmed_str);
// Heap allocate a string
let alice = String::from("I like dogs");
// Allocate new memory and store the...
Rust by Example
Book
2024-01-01
~4 min read
whileydave.com
...usize = __nondet();
// Apply Constraints
__VERIFIER_assume(len <= LIMIT);
__VERIFIER_assume(i < len);
__VERIFIER_assume(xs[i] == x);
// Compute result
let result = index_of(&xs[..len],x);
// Check it matches
assert!(xs[result] == x);
}
This is roughly similar to before, except we now require some i
where xs[i] == x. Also...
Observations/Thoughts
2021-10-27
~6 min read
docs.rs
...use tree_sitter_highlight::HighlightEvent; let highlights = highlighter.highlight( &javascript_config, b"const x = new Y();", None, |_| None ).unwrap(); for event in highlights { match event.unwrap() { HighlightEvent::Source {start, end} => { eprintln!("source: {start}-{end}"); }, HighlightEvent::HighlightStart(s) => { eprintln!("highlight style started: {s:?}"); }, HighlightEvent::HighlightEnd => { eprintln!("highlight style ended"); }, } } The last...
Crate
v0.26.11
2026-07-12
www.shuttle.rs
...We want to check the row with that username has a password that matches. If the credentials match then we create a new session:
Then we refer back to the signup section and replicate the same HTML form and handler that renders the Tera template as seen before but for...
Observations/Thoughts
2022-08-31
~12 min read
rustc-dev-guide.rust-lang.org
...Destruction scopes are also made explicit.
•
Statements, expressions, match arms, blocks, and parameters are stored separately. For example, statements in the stmts array reference expressions by their index (represented as a ExprId) in the exprs array.
The THIR lives in rustc_mir_build::thir. To construct a thir::Expr, you...
Guide to Rustc Development
Book
2024-01-01
~4 min read