psznm

July 22, 2026, 8:55pm 1

I have found myself feeling not great about my codebase because so many things can not be moved/copied due to internal dependencies. The worst thing about this is that it spreads like disease. If a low level structure can not be moved, any structure that uses it also can not be moved, and that bubbles up. What makes matters worse is that spotting what can or can not be moved/copied is not trivial. I’ve found ways to mitigate the issues with this.


One problem I found was that the initialization of structs that hold these immovable structs was fragmented. So initially I was doing something like

self.* = .{
    .pin = .init(),
    .movable = .init(),
    .immovable = undefined,
};
self.pin.lock();
self.immovable.init();

But this was error prone, so I found I could initialize these structs at once which improved things.

self.* = .{
    .pin = .initAddrLocked(&self.pin),
    .movable = .init(),
    .immovable = immovable: {
        self.immovable.init();
        break :immovable self.immovable;
    },

The other big problem is actually knowing what may be copied. Initially initialization pattern was the only clue I could find. The “pin” helps with that since I can clearly see on inspection of the structure, but it required jumping through hoops - it is not something I can see just from seeing the variable. Also it doesn’t help with code that I do not own.

Everything works. Perfectly. But it just doesn’t feel good. It would be much better if immovable structures were rarity instead of majority.


Stdlib has this mostly solved by not having internal dependencies and letting user provide the buffers and other things. In user code these buffers have to live somewhere obviously, so that approach does not work as well.

I have a hunch that I am just too reluctant to using allocators to actually put internal dependencies on heap, but doing an allocation for small size that is comptime known feels wrong to me. Also it then requires passing allocator where it feels like one shouldn’t be needed.

How can I escape this “immovable hell” and make my codebase feel good again?