glitch.land ✧♡꒰˘̩̩̩⌣˘̩̩̩๑꒱☼
| Software | Books | Micros | URLs | Me | ⤻GitHub | ⤻Itch.io

Recent Posts

A byte-sized unique identifier Printing In Virtual Reality Emulating CHIP-8

Webgl Boids

Exploring and simulating flocking using webgl and boids rules
September 24, 2023 • 4 min read •
3d algorithms random nature webgl

WebAudio Worklet

Explore processing audio in a separate thread using WebAudio Audio Worklets.
September 19, 2023 • 6 min read •
algorithms audio voice-training

Vocal Underdoer

MtF Voice Training, are you a vocal underdoer too?
September 17, 2023 • 2 min read •
personal trans voice-training
Prev 1 2 3 4 5 6 7 8 Next

MICRO - FEED

2026-02-13 11:46:27 Rust Non-Lexical Lifetimes

Sorry for lack of content, I’m still alive, life has just been very hard. I will try to get back to writing more ❤️.

I was doing a quiz on rust lifetimes last night, and got the following question wrong. Will this code compile?

let mut v = vec![1, 2, 3];
let a = &v[0];
println!("{a}");
v.push(4);
Click here to see the answer :)

I thought it would not compile, because a takes read ownership, and push needs read + write access. But I was wrong!

It does compile! It’s due to a Rust feature called Non-Lexical Lifetimes (added in 2018). So along with the other rules, the borrow checker also asks: “Is there any path where the borrow is used after this point?” If the answer is no, the borrow ends there!

  let mut v = vec![1, 2, 3];
  let a = &v[0];      // immutable borrow starts
  println!("{a}");    // last use of `a` - borrow ENDS here with NLL
  v.push(4);          // RW mutable borrow is fine, no conflict

I hope this helps others learning Rust (its a beautiful language)

Read more
2025-06-24 11:30:18 Micros

Even when I’m super busy :D

Read more
View All Micros
© 2026 glitch.land. All rights reserved.