Add Buffer type field as PhantomData. #1
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add PhantomData type to Buffer indicating the type of data the Buffer points to. There is an example in Unused type parameter section of the PhantomData marker docs.
The sole purpose of the type field is to help Rust compiler's type checking, preventing accidentally reading to result array of another type or writing data with different type using CommandQueue's
enqueue_
methods. The field is hidden in docs becaue it has size of zero bytes i.e. it doesn't exist at runtime. This hiding in the docs has been the choice e.g. in euclid math tools crate.If data with different type needs to be written or read into result array of another type however, the type parameter can be explicitly cast with the
cast()
method, which essentially creates a clone of the Buffer with the new type. Although other methods for achieving the same would exist, such as casting the data to correct type before writing or after reading to result array.