Type alias for generic

Hey all,

I have a struct that holds a seedable RNG, like so:

RngCont<ChaCha8>

I pass it as a parameter to several methods, and I'd like to not have to identify the seedable RNG every time. I'd rather pass around something that aliases this type; naively something like:

type ProgRng = RngCont<ChaCha8>;

And just use ProgRng everywhere. Am I missing something obvious? Should I be using a new type for this?

Thanks for your help.

That alias should work. Remember, you'll have to import it into other modules, just like every other top level item

1 Like

Alternatively, if this is your struct, you can define a default for the type parameter:

struct RngCont<Rng = ChaCha8> { /* ... */ }

If you do this, any code that specifies RngCont without a type parameter is actually referring to RngCont<ChaCha8>.

1 Like

Thanks @2e71828 and @RustyYato for your quick answers; I've marked Rusty as the Solution, but I'm now aware that a default value is possible, which is cool.

I was sure I tried that last night; lesson learned, no more programming after the kids go to bed!

Thanks to you both