#Idiomatic constructor name when pointer provided by caller?

1 messages · Page 1 of 1 (latest)

lilac hill
#

I have a struct that requires a stable pointer AND some initialization. Typically init returns a struct value, create takes an allocator and returns a pointer. Is there an idiomatic method name that takes the out pointer and writes to it?

i.e. pub fn abcd(out: *T) void

mint osprey
#

I would still call that function init

#

But if you don't like that, maybe setup or something?

#

Generally I'd try and avoid that type of constructor though; the only usecase is pinned datastructures which are often not a great idea

lilac hill
#

In this case its necessary since the struct contains a MPSC queue that is used by many threads, so the queue must be stable.

#

Its an event loop

mint osprey
#

Fair enough, that's one of the few cases where it's justified :)