What problem does this solve or what need does it fill?
Selecting random elements is a common gameplay tasks. We can quickly and ergonomically generate possible lists of
What solution would you like?
Implement the SliceRandom trait for Query.
Nope, this is not publically implementable. We have to use the alternative, implementing it for our associated iterator type.
Create an example.
What alternative(s) have you considered?
- Users could manually implement this functionality each time. This is tedious, error prone and probably slower.
- We could create our own methods that do this. This breaks from the ecosystem standard for no good reason.
- We could implement the
IteratorRandom trait instead. Taking a look, our ability to mutate the elements of the query + desire to be able to shuffle the order probably makes SliceRandom more fitting. More importantly, Query isn't itself an iterator (nor should it be): being able to operate directly on a query rather than query.iter() is more natural and convenient.
Additional context
Related to #1470.
What problem does this solve or what need does it fill?
Selecting random elements is a common gameplay tasks. We can quickly and ergonomically generate possible lists of
What solution would you like?
Implement the SliceRandom trait forQuery.Nope, this is not publically implementable. We have to use the alternative, implementing it for our associated iterator type.
Create an example.
What alternative(s) have you considered?
IteratorRandomtrait instead. Taking a look, our ability to mutate the elements of the query + desire to be able to shuffle the order probably makesSliceRandommore fitting. More importantly,Queryisn't itself an iterator (nor should it be): being able to operate directly on a query rather thanquery.iter()is more natural and convenient.Additional context
Related to #1470.