tweedegolf.nl
...Token, cx: &mut Context) -> Poll<io::Result<()>> {
let mut guard = self.statuses.lock().unwrap();
match guard.entry(token) {
Entry::Vacant(vacant) => {
vacant.insert(Status::Awaited(cx.waker().clone()));
Poll::Pending
}
Entry::Occupied(mut occupied) => {
match occupied.get() {
Status::Awaited(waker) => {
// skip clone is wakers are the same
if !waker.will...
Rust Walkthroughs
2024-02-28
~19 min read
llogiq.github.io
...So I
randomly commented out code sections and found that the part where we find the
replaced sequence length and count matches in parallel (using rayon to join the
threads) caused the error.
However, somewhat surprisingly, removing the threads and running the code on
the main thread did not solve...
News & Blog Posts
2019-10-01
~2 min read
kerkour.com
...Building HTTP client");
// will match https://...?page=XXX
let page_regex =
Regex::new(".*page=([0-9]*).*").expect("spiders/github: Compiling page regex");
GitHubSpider {
http_client,
page_regex,
expected_number_of_results: 100,
}
}
}
Extracting the item is just a matter of parsing the JSON, which is easy thanks to reqwest, which...
Rust Walkthroughs
2022-05-11
~2 min read
bodil.lol
...usize },}
The update function needs a match clause to respond to our new message by updating the model:
fn update(&mut self, msg: Self::Message) -> UpdateAction<Self> { match msg { ... Message::Filter{filter} =>{ self.filter = filter; UpdateAction::Render } }}
And, finally, we need to attach a callback to our subcomponent to find...
News & Blog Posts
2020-02-25
~53 min read
minikin.me
...RefCell::new(None) }
}
fn area(&self) -> f64 {
let mut cache = self.cached_area.borrow_mut();
match *cache {
Some(area) => {
println!("Returning cached area: {}", area);
area
}
None => {
println!("Computing area...");
let area = self.width * self.height;
// Only for debugging purposes to track how many times the area is actually computed.
COMPUTE...
Observations/Thoughts
2025-02-05
~7 min read
aturon.github.io
...Note that compare_and_swap atomically changes the value of an AtomicPtr
from an old value to a new value, if the old value matched. Also, for this post
you can safely ignore the Acquire, Release and Relaxed labels if you’re
not familiar with them.
impl<T> Stack<T...
From the Blogosphere
2015-08-31
~20 min read
blog.singleton.io
...Here you can see a closure in Rust and the extremely versatile match block and Option enum which reminds me of Scala code.
|texture: &Option<(Vec<u8>, usize, usize, String)>| {
match texture {
Some(tuple) => tuple.3.clone(),
None => "".to_string(),
}
}
In fact writing Rust code reminds me most of writing...
Rust Walkthroughs
2022-01-05
~20 min read
tweedegolf.nl
...Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// Ignoring pin projection here
loop {
match self {
Unresumed { input } => {
let blah = input > 10; // Preamble
*self = BarFut::Inlined { foo: foo(blah) };
},
Inlined { foo } => {
break foo
.poll(cx)
.map(|result| result * 2) // Postamble
},
}
}
}
}
That's a lot better than what's currently generated...
Observations/Thoughts
2026-05-06
~11 min read
weihanglo.tw
...It can be a wrapper of Cargo or use cargo-the-library.Matching the result of dependency resolutionIn an ideal world, a published crate on crates.io is guaranteed to be buildable. Other developers can fetch its source and build it flawlessly. This guarantee is upheld with the Cargo ad...
Observations/Thoughts
2024-07-17
~15 min read
jduchniewicz.com
...Option<HitRecord> = None;
let mut closest_so_far = t_max;
for object in &self.objects {
match object.hit(ray, t_min, closest_so_far) {
Some(rec) => {
closest_so_far = rec.t;
temp_rec.replace(rec);
}
None => {}
}
}
temp_rec
}
}
Notice how the bool variable is gone and the code seems to...
Miscellaneous
2021-03-17
~25 min read
jduchniewicz.com
...Option<HitRecord> = None;
let mut closest_so_far = t_max;
for object in &self.objects {
match object.hit(ray, t_min, closest_so_far) {
Some(rec) => {
closest_so_far = rec.t;
temp_rec.replace(rec);
}
None => {}
}
}
temp_rec
}
}
Notice how the bool variable is gone and the code seems to...
Rust Walkthroughs
2021-03-03
~25 min read
blog.kuviman.com
...Not really knowing what exactly we were going to make, I started making the things we thought would match any theme. The first thing I did was limited view and generating objects only outside of it. Next, I made it so players could move towards the tile they clicked on...
Observations/Thoughts
2020-10-28
~7 min read
burn.dev
...To preserve the previous behavior, make sure to specify the matching options:
- let output = tensor.grid_sample_2d(grid, InterpolateMode::Bilinear);
+ let options = GridSampleOptions::new(InterpolateMode::Bilinear)
+ .with_padding_mode(GridSamplePaddingMode::Border)
+ .with_align_corners(true);
+ let output = tensor.grid_sample_2d(grid, options); QuantStore
The QuantStore variants used in...
Project/Tooling Updates
2026-01-21
~6 min read
hiddentao.com
...The contract checks to ensure that the obfuscated version of this matches what the user last sent in during the commit phase. The user's vote only counts towards the final tally if there is a match. Note that users can perform this action once.
Anyone can query the contract...
Learn More Rust
2020-08-18
~11 min read
notgull.net
...let waker = this.waker_for_slot(index, cx.waker());
let mut slot_context = Context::from_waker(&waker);
let future_slot = match this.futures.get_mut(index) {
Some(slot) => slot,
None => continue
};
if let Some(future) = future_slot.as_mut() {
// Try to poll this future.
match future.as_mut().poll(&mut...
Observations/Thoughts
2024-04-03
~11 min read
jack.wrenn.fyi
...In the mean time, use offset_of! and the static_assertions crate to test that your layouts match your expectations.
repr(C) layouts are not always SemVer stable
The limitations of repr(C) are not only technical, but also social. The central social contract of Rust’s crate authors is...
Observations/Thoughts
2024-07-31
~3 min read
o-santi.github.io
...want to match 3 words of 2 digit numbers followed by a capital letter? great, they can do that. want to match balanced parenthesized expressions? sadly, regex is incapable of ever solving that, because that language is not regular, so no matter how hard you try it will never solve...
Observations/Thoughts
2024-06-05
~12 min read
adotinthevoid.github.io
...For
example
cargo-check-external-types first attempts to deserialize just the format
version, and bails if that doesn’t match. This means the user receives an
error about the version of nightly being wrong, which is much more useful and
actionable than an error about a missing or unknown...
Observations/Thoughts
2023-01-04
~11 min read
leod.github.io
...gl::Program<U, V, F> = gl.create_program(
vertex_shader,
fragment_shader,
)?;
program
.with_uniforms(/* uniform bindings matching U */)
.with_framebuffer(/* framebuffer matching F */)
.with_settings(/* draw settings */)
.draw(/* vertex specification matching V */)?;
Shader functions are written as normal Rust code that interacts with types from posh::sl, thereby leveraging...
Observations/Thoughts
2023-06-07
~32 min read
doc.rust-lang.org
...If the pattern does not match (this requires it to be refutable), the else block is executed. The else block must always diverge (evaluate to the never type).
let (mut v, w) = (vec![1, 2, 3], 42); // The bindings may be mut or const
let Some(t) = v.pop() else...
The Rust Reference
Book
2024-01-01
~3 min read