Julian way of expressing a buffer swap

Yes, I was thinking of the ”state as immutable struct” version as enforcing a logic similar to a state monad in Haskell, which certainly makes thread safety easier to enforce.