#cast const to var
1 messages · Page 1 of 1 (latest)
You can make your lib return a pointer of the right constness
Just use anytype as the receiver param and then do some comptime stuff to figure out the return type
Much better than doing @constCasts to get rid of the constness after the fact
That's often caused by const key = ... instead of var key = ...
If it's a proc param though, consider changing charAt to fn charAt(self: *const String, index: usize)
Otherwise, yes, you'll need var copy = param; or whathaveyou. But it sounds odd to require a mutable string in order to know what char is at a particular index, so I'd probably change that anyway.