Hoverbear

hoverbear.org · Personal blog · on HN since 2014

Hoverbear writes about Rust, PostgreSQL, and NixOS, including state machine patterns, Raft, and Rust on the web.

What HN saysHN commenters cite its Rust state machine pattern post, with one noting its enum approach avoids dynamic dispatch and makes state data easier to reach.
30HN people shared it
13linked it in comments
23stories submitted
613story points
2 years agolast shared
2014people per year2026

Most-shared posts

  1. 1
    Pretty State Machine Patterns in Rust (2016)
    8 people · 140 points · first shared 2019 · 50 comments on HN
  2. 2
    Pretty State Machine Patterns in Rust
    5 people · 62 points · first shared 2016 · 3 comments on HN
  3. 3
    Hierarchical Structures in PostgreSQL (2020)
    3 people · 251 points · first shared 2021 · 50 comments on HN
  4. 4
    Declarative Gnome Configuration with NixOS
    3 people · 5 points · first shared 2022 · 2 comments on HN
  5. 5
    The Path to Rust on the Web
    2 people · 5 points · first shared 2017 · discussion on HN
  6. 6
    Option Monads in Rust
    1 people · 83 points · first shared 2014 · 57 comments on HN
  7. 7
    Getting acquainted with Rust's mio
    1 people · 36 points · first shared 2015 · 23 comments on HN
  8. 8
    Option Monads in Rust
    1 people · 15 points · first shared 2014 · discussion on HN
  9. 9
  10. 10
    Raft so far
    1 people · 2 points · first shared 2015 · discussion on HN
  11. 11
    Configurable Nix Packages
    1 people · 2 points · first shared 2022 · discussion on HN
  12. 12
    Raft (in Rust) so far
    1 people · 2 points · first shared 2015 · discussion on HN
  13. 13
    A journey into iterators
    1 people · 2 points · first shared 2015 · discussion on HN
  14. 14
    Rust, Travis, and GitHub Pages in Harmony
    1 people · 2 points · first shared 2015 · discussion on HN
  15. 15
    Declarative Gnome Configuration with NixOS
    1 people · 1 points · first shared 2023 · discussion on HN

What HN people wrote when they linked it

MarkSweep · 2025-04-20
It's to create random numbers to make the star field on the home page: https://hoverbear.org/ It's defined in this file: https://github.com/Hoverbear/hoverbear.org/blob/root/sass/_magic.scss Which links to an explanation here: https://medium.com/hypersphere-codes/counting-in-css-unlock-magic-of-c…
kd5bjo · 2020-04-01
The cited post[1] recommends an enum for this job, which avoids the dynamic dispatch and makes it easier to get at a specific state’s data when you have the whole machine. [1] https://hoverbear.org/blog/rust-state-machine-pattern/
cies · 2019-10-31
https://hoverbear.org/blog/rust-state-machine-pattern/ Here another article, but with a more classical state machine impl.
papaf · 2020-10-24
Please don't let my negative experience put you off learning Rust -- its an important language and worth putting the effort in. I would recommend diving in and seeing if it works for you. For informational purposes, this is what I still find difficult: - The module system. It constantly catches me out. - I think that I understand traits but struggle using libraries that have a lot of traits in the public interface. - Error handling is nice but there are error handling libraries going in and out of fashion every few months. Which one do I use? - Callbacks combined with the borrow checker. - Complexity of idiomatic code such as state machines [1]. - The strict string handling. What about strings that should be UTF-8 but come over a network protocol? - Combining async code with non-async code. Also, how do you write a library that does I/O and supports both sync and async? - Iterators. I have some functional programming experience but I hit problems with iterators combined with the borrow checker. [1] This example has just 3 states and is much simpler than most real world examples: https://hoverbear.org/blog/rust-state-machine-pattern/
arcticbull · 2019-07-12
The borrow checker isn't nearly as big a deal as you make it out to be from a complexity perspective. You have to take some time to learn the paradigm but when you do it's easy. The challenge is people assume it writes like C because it looks like C, and are frustrated when it doesn't. After a couple of months, you'll realize the borrow checker is your friend, you just need to feed it stuff in a way it understands. The borrow checker is great for all sorts of things, like ensuring that you only have a single mutable reference or an arbitrary number of immutable references to objects (to prevent corruption) and for the pseudo-threaded model interrupts entail. Memory safety matters in embedded systems, too. You can encode state cleanly with ADT enums [2] where the language can statically detect invalid state transitions. It's also a much more expressive language, providing you with great abstractions with no added cost. The ergonomics are pretty great compared to dealing with C once your peripherals / register accesses are wrapped, as often are already. For instance, check out the stm32 package [1]. Being able to rely on the compiler more means you get correct code faster, and debugging on embedded systems can be absolute hell. Anything that helps me avoid it is a massive win in my books. [1] https://github.com/stm32-rs/stm32-rs [2] https://hoverbear.org/2016/10/12/rust-state-machine-pattern/
Animats · 2015-01-24
That's a legitimate criticism. As of yesterday, how to convert "String" to "&str" still wasn't nailed down. (".as_string(), or "&[]"?). Things are far better than they were a month ago, though. After using Rust a little, I get the feeling that the borrow system, the big innovation, is in good shape. The type system is clunky. Take a look at this date/time module: https://github.com/lifthrasiir/rust-chrono/blob/master/src/datetime.rs Note that none of this code does any computation. It's all field access and update. It's not a multi-calendar system with time zone tables. This is the code for stuffing the year into a Datetime object: #[inline] fn with_year(&self, year: i32) -> Option<DateTime<Off>> { self.local().with_year(year).and_then(|datetime| self.offset.from_local_datetime(&datetime).single()) } This has generics and a closure, neither of which ought to be necessary. Despite all this generality, there are two copies of this code, one for time-zone aware and one for "naive" timestamps. The author of that module has misgivings about the structure. He writes "This is a bit verbose due to Rust's lack of function and method overloading, but in turn we get a rich combination of initialization methods." This is the best of the three date-time modules available; the other two won't even compile with the current build system and are abandoned. There are some neat ideas in the type system. One is that if you have something which might not be…
milliams · 2023-09-22
I found this (old [2016] but still relevant) blog post expanding on this at https://hoverbear.org/blog/rust-state-machine-pattern/ which was very useful for describing type-safe state machines in Rust.
ForHackernews · 2023-03-31
I can't believe this article doesn't mention the (first-party) ltree extension: https://hoverbear.org/blog/postgresql-hierarchical-structures/#solutio…
johndoe0815 · 2022-06-17
__jem · 2021-01-19
Here's a good blog on the topic: https://hoverbear.org/blog/rust-state-machine-pattern/. The last implementation of Raft uses this pattern.
epage · 2018-03-01
To me, the power of it isn't just in dynamic memory but also in that Rust has clear move vs ref vs bit copy vs logical copy (clone) and use-after-free protection. As one example of the benefit of this. This makes me feel a lot more comfortable writing state machines in Rust's type system. See https://hoverbear.org/2016/10/12/rust-state-machine-pattern/
zcdziura · 2017-06-26
There was an article posted here a while back on how to implement a state machine in Rust, purely using its type system to facilitate state transitions. It's a neat concept, even if it's a bit more verbose than what you'll find in other languages. https://hoverbear.org/2016/10/12/rust-state-machine-pattern/
Ar-Curunir · 2016-12-29
There are ways to prevent some logic/protocol problems at the type level using rust: https://hoverbear.org/2016/10/12/rust-state-machine-pattern/ https://blog.tarn-vedra.de/posts/phantom-types-for-safe-apis.html https://insanitybit.github.io/2016/05/30/beyond-memory-safety-with-typ… https://scribbles.pascalhertleif.de/elegant-apis-in-rust.html#session-… Some libraries use such features to prevent certain kinds of nonce-reuse during encryption (one of the more common ways of screwing up encryption). These constraints are checked at compile-time. Such guarantees are not possible with weaker type systems like that of C.

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close