I think I see your point now, thanks for explaining. You are right, I
should avoid having this sense of "type security". The `Pointer[]` library
is only doing syntatic sugar around the fundamentally unsafe casting of an
`unsafe.Pointer`.
Having said that, unfortunately limiting it to a list of
The thing is, if it works with an arbitrary pointer type, it also works
with `*[1<<30]byte`, giving unsafe memory access to essentially the entire
memory space. Without any additional safeguards. You say it would "feel
cleaner without the additional lines of unsafe.Pointer floating around",
but tha
Thanks for the suggestions Alex. Interesting that enumerating the pointers
in a constraint would work ... but it makes sense.
I think I disagree with the statement about not wanting to allow any
pointer type. From my project perspective there will be indeed a limited
number of those (~10). But
I guess thinking about some more, I don't really understand the point of
what you're doing. It seems you *can* actually get the static guarantee you
want - you just have to spell the call
`(*C.mystruct)(UnsafePointerOrError(s))` instead of
`PointerOrError[C.mystruct](s)`. If you *could* restrict th
You should be able to instantiate the function using a Pointer. That is,
you can write
func PointerOrError[T any](s C.StatusOr) (t T, err error) {
var ptr unsafe.Pointer
ptr, err = UnsafePointerOrError(s) // <-- unsafe.Pointer, error
if err != nil {
return