I'm following a rust course and I've a hit some confusion with a function in the code that looks to me to be a recursive function, but the instructor hasn't said anything about it being recursive. And recursive or not, I'm not understanding how the function works. My confusion is with the 2nd line in the function where it seems to be calling itself, but I don't see return or implicit return anywhere in sight, and again, the instructor isn't covering recursive functions at all at this point as far as I can tell.
This is calling a differentshuffle method; the one defined by the cards field. In this case, it’s provided by the SliceRandom trait which you’re useing in the top line of the program.
Neither of these methods return anything of interest; they instead modify the held items through the &mut self reference.
SliceRandom is a trait, which means that it adds new methods to whatever type it’s implemented for. In particular, SliceRandom is implemented for slices [T], giving them a shuffle method.
Thanks again. I wish the instructor had explained that a bit, not sure how anyone taking that course would know that these are two different shuffle functions. I wish the one implemented with SliceRandom would have been written more like one of these:
SliceRandom::shuffle,
rand::shuffle, or
thread_rng:shuffle
something to let me know it's not the same shuffle.
Anyway, thanks again, I appreciate the clairification.
Tiny nit, this needs to be a reborrow &mut *self.cards for this call to work, because deref coercion happens as part of method call resolution which is not applied with fully qualified syntax or the Trait::method shorthand.