willcrichton.net
...Chan<(Offer<_,_>, ()), Offer<_,_>> = c.label();
loop {
c = match c.offer() {
Branch::Left(c) => {
let c: Chan<_, Recv<_,_>> = c.send(Ping);
let (c, Ping): (Chan<_, Goto<_>>, _) = c.recv();
c.goto()
},
Branch::Right(c) => {
c.close();
return;
}
}
}
}
Note that the Chan has two type arguments: an environment Env and a current action...
News & Blog Posts
2020-05-05
~15 min read
willcrichton.net
...Chan<(Offer<_,_>, ()), Offer<_,_>> = c.label();
loop {
c = match c.offer() {
Branch::Left(c) => {
let c: Chan<_, Recv<_,_>> = c.send(Ping);
let (c, Ping): (Chan<_, Goto<_>>, _) = c.recv();
c.goto()
},
Branch::Right(c) => {
c.close();
return;
}
}
}
}
Note that the Chan has two type arguments: an environment Env and a current action...
Learn More Rust
2020-09-30
~15 min read
rust-osdev.com
...repr(packed) structures are very common in OS Dev, and make sure the layout of Rust's structures matches the
hardware's. Unfortunately, they can be slightly tricky to work with - creating an unaligned reference is
undefined behaviour, and references can transiently be created by, for example, calling a method...
Newsletters
2021-07-14
~3 min read
bencher.dev
...fn main() { for i in 1..=100 { match (i % 3, i % 5) { (0, 0) => println!("FizzBuzz"), (0, _) => println!("Fizz"), (_, 0) => println!("Buzz"), (_, _) => println!("{i}"), } }}
Create a main function
Iterate from 1 to 100 inclusively.
For each number, calculate the modulus (remainder after division) for both 3 and 5.
Pattern match...
Observations/Thoughts
2024-01-31
~18 min read
rickyhan.com
...TyIdent(
'70,
"x"
)
}
],
ret_ty: '73
}
)
}
],
ret_ty: '74
}
),
ty: '75
}
}
}
]
}
)
]
)
Also, it is not mutually exclusive with impl Debug for individual components, for example:impl Debug for Type {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
use self::Type::*;
match self {
Unit => write!(f, "()"),
INT => write!(f, "int"),
BOOL...
News & Blog Posts
2018-04-17
~5 min read
matklad.github.io
...during runtime, actual types of all the values
match inferred static types of variables.
Rust’s unsafe is similar: if we verify every usage of
unsafe (local property!) to be correct, then we guarantee
that the program as a whole does not contain undefined behavior.
The devil is in the...
News & Blog Posts
2019-07-30
~3 min read
rust-lang.github.io
...Users who need such a feature will need to write (or generate) big match statements and hope they optimize well (this has been servo's approach).
2. Directly stabilize the discriminant_value intrinsic, or a wrapper that doesn't use an opaque newtype. This more drastically precludes future enum representation...
RFC 1696
RFC
2016-08-01
~4 min read
fasterthanli.me
...Context) -> HttpResult {
if cx.path.ends_with('/') && cx.path != "/" {
return serve_redirect(cx.path.trim_end_matches('/')).await;
}
if cx.path == "/robots.txt" {
return Ok(Box::new(
Response::builder()
.status(StatusCode::OK)
.body(Body::empty()),
));
}
if cx.path == "/tags" {
return tags::serve_list(cx).await;
} else if cx.path.starts...
Rust Walkthroughs
2022-11-30
~16 min read
blog.reverberate.org
...In fact, this blog entry was
originally going to be an argument for why Rust cannot match C for upb’s use
case.
But I recently discovered a technique that shifted my thinking a lot. I call
it “No-Panic Rust”, and while the technique is clearly not new1, I...
Observations/Thoughts
2025-02-05
~15 min read
db48x.net
...Option<EmacsDouble>) -> EmacsDouble {
match x {
None => y.atan(),
Some(x) => y.atan2(x)
}
}
You can see that we don't have to check to see if our
arguments are of the correct type; the code generated by
the lisp_fn macro does this for us. We also asked
for the...
News & Blog Posts
2018-10-09
~9 min read
blog.logrocket.com
...struct DataSerializer<'a> {
data: &'a StoredData,
}
impl Serializer for DataSerializer<'_> {
fn root(&self) -> Option<&str> { None }
fn build(&self, json: &mut jsonway::ObjectBuilder) {
let data = &self.data;
use StoredVariant::*;
json.object("variant", |json| match data.variant {
YesNo(b) => { json.set("YesNo", b) },
Small(u) => { json.set("Small", u) },
Signy(i...
Observations/Thoughts
2020-09-04
~14 min read
kunobi.ninja
...The operator's job is to keep reality matching it, continuously. This is the reason kobe is an operator rather than a provisioning script: nothing about a pool is a one-shot action. A pool is a target the controller keeps converging on, so drift away from it (a cluster...
Project/Tooling Updates
2026-08-05
~9 min read
fnordig.de
...Vec<u8>) -> TestResult {
let compr = match compress(&data) {
Ok(compr) => compr,
Err(LzfError::NoCompressionPossible) => return TestResult::discard(),
Err(LzfError::DataCorrupted) => return TestResult::discard(),
e @ _ => panic!(e),
};
let decompr = decompress(&compr, data.len()).unwrap();
TestResult::from_bool(data == decompr)
}
Of course we need to test this.
QuickCheck handles the heavy part...
News & Blog Posts
2016-05-16
~4 min read
rerun.io
...It's pure Rust with no dependencies, compiles to wasm easily and is designed to match d3-force as close as possible.
It's been working great for us so far and can hopefully be useful others in the community as well.Try it out and let us know what...
Project/Tooling Updates
2024-12-18
~3 min read
pkolaczk.github.io
...by shortening the lifetime of the outer scope to match the lifetime of the inner scope,
nor by extending the lifetime of the inner scope to match the outer scope.
This means we can’t put references to two scopes into a single vector, at least not without changing the...
Learn More Rust
2020-09-04
~15 min read
bluishcoder.co.nz
...Fragment) -> ~str {
match s {
Str(s) => { s }
}
}
fn render_page(s: Fragment) {
println(get_str(s));
}
Functions exist to generate the head and body of the page with the latter including some form of data obtained elsewhere. Perhaps user input or the output of some other process:
fn get_head...
Notable discourse
2013-08-19
~9 min read
timofreiberg.github.io
...Vec<_> = self
.old_rules
.iter()
// 👇 this filter should be fast
.filter(|vs| matcher.matches_inlined(vs))
.copied()
// 👇 heap allocation
// how about you do something about this, past Timo!
.collect();
let new_rules: Vec<_> = self
.new_rules
.iter()
.filter(|vs| matcher.matches_inlined(vs))
.copied()
.collect();
// 👇 the path values are very...
Observations/Thoughts
2020-12-23
~15 min read
onevariable.com
...core::ptr::NonNull<()>,
) -> Result<(), ()> {
let mut variant = core::mem::MaybeUninit::<u32>::uninit();
::postcard_forth::impls::deser_u32(
stream,
core::ptr::NonNull::from(&mut variant).cast(),
)?;
let variant = variant.assume_init();
match variant {
0u32 => {
let mut a = core::mem::MaybeUninit::<Alpha>::uninit();
::postcard_forth::deser_fields_ref(stream, &mut a)?;
base...
Observations/Thoughts
2024-06-12
~8 min read
www.sheshbabu.com
...Tooling Ecosystem Overview
Variables and Data Types
Functions and Control Flow
Pattern Matching and Enums
FunctionsRust’s function syntax is pretty much similar to the one in JavaScript.
fn main() {
let income = 100;
let tax = calculate_tax(income);
println!("{}", tax);
}
fn calculate_tax(income: i32) -> i32 {
return income * 90 / 100...
News & Blog Posts
2020-07-08
~4 min read
slint-ui.com
...Also fixed assert to match the octospi
controller for the hyperram (1 instead of 2).
I get asserts in the stm32h7 crate above that, although
the data sheet
says the CPU can go up to 550Mhz.
swrenderer: Optimize image drawing by using premultiplied colors (#1339)
Make the Pico use interrupts...
Project/Tooling Updates
2022-06-22
~4 min read