~/talk

The Guard pattern in Rust

Talkat RustLab 2024 · 2024-11-09..11-11· [rust, software-architecture]
slides:none on file

Explains the Guard pattern as a concrete Rust idiom: a lock guard type that proves invariants at compile time and unlocks on Drop, applied to a Postgres-backed PG mutex implemented with advisory locks and used in the EventSourceRS library for pessimistic locking; it works for low contention but causes connection-pool starvation unless paired with try_acquire, involves tricky self-referential lifetimes and async-drop problems, and shows a simpler scope guard wrapper around a closure that can be dismissed.

AI-written summary · about

  1. 0:00Guard pattern intro
  2. 2:35Naive mutex problems
  3. 5:27RAII and Guard definition
  4. 8:16Guard enforces invariants
  5. 10:03PostgreSQL use case
  6. 13:44Lessons and sync pitfalls
  7. 15:29ScopeGuard in Linux kernel
  8. 18:44Guard caveats
  9. 19:27Summary
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.