How to explicitly set the args

pub struct TestStruct<T: str+usize>{              // of course this is incorrect, but don't know how to set it.
    pub data: Vec<T>
}

normally use the T generics, but for some special cases , I want to explicitly set the args type such as : &str or usize.
how to write this ristriction?
thanks advanced.

You mean specialization? That is currently not supported.

1 Like

ok, thanks..

You can write different implementations for the concrete types TestStruct<&'_ str> and TestStruct<usize>. Although that seems like a weird requirement. Can't you just implement a custom trait for str and usize instead?

2 Likes

great idea, thanks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.