What do do with unused types in generics?


I have a generic struct like:

struct Node<T> {
   payload: T

I want to allow clients to associate data with this struct, so I provide the payload field.

But in some cases when using Node I just want to use the struct and I don’t care about associating any payload. Is there some zero sized type that I can use to indicate that the value isn’t being used for this particular Node configuration?

At the moment I do something like this:

let v: Vec<Node<bool>> = Vec::new();

Using bool because I assume it won’t take much space. But that doesn’t communicate that I am not actually using the payload for anything in this case.


I think you can use (), that is, Node<()>.


You are right, I should have remembered that by now. Thanks!

1 Like