decline-cookies / anvil-unity-dots

Unity DOTS and ECS specific additions and extensions to Anvil
MIT License
4 stars 1 forks source link

EnumToFixedStringExtension and EnumerableToFixedStringExtension - Readonly #277

Closed mbaker3 closed 1 year ago

mbaker3 commented 1 year ago

Add readonly reference support for the ToFixedString extensions

What is the current behaviour?

A collection must be passed with a ref which means that any readonly references cannot make use of these extension methods.

What is the new behaviour?

Collections are now pass in with the readonly reference in so that readonly referenced collections can now leverage the extension methods.

To accomplish this we're using Unity's dangerous UnsafeUtilityExtensions.AsRef to transform a readonly reference into a read/write reference. This is fine because none of our operations cause a mutation to the instance. We just create an enumerator and enumerate. This wouldn't be required if Unity marked their GetEnumerator() methods with readonly

What issues does this resolve?

What PRs does this depend on?

Does this introduce a breaking change?