logoalt Hacker News

bsaulyesterday at 3:54 PM2 repliesview on HN

how do apis typically manage to actually « use » the « bar » of your example, such as storing it somewhere, without enforcing some kind of constraints ?


Replies

steveklabnikyesterday at 3:57 PM

"BarTrait" is the constraint.

This is monomorphized for every type you pass in, in short.

Maxataryesterday at 6:58 PM

If you need to store the value then you have no choice but to take in a dyn trait.

show 2 replies