#Why does Self in this generic need to be a pointer?

1 messages · Page 1 of 1 (latest)

lyric fog
#

I see the same in the std lib ArrayList, I wonder if it's like Go when you need a pointer receiver to modify self?

coarse raft
#

if self isn't a pointer, it's passed by value. so if zig allowed self.length += 1, it would update length from 3 to 4, return from the function, and the caller would still see .length as 3. by making it a pointer, it doesn't copy it