Trait bounds (T: Trait, where)
Në shqip: Kufizimet me trait
ShpjegimiSQ
Me T: Display ose where T: Clone kufizon një gjenerik: „çfarëdo tipi, mjafton të dijë të bëjë këtë“. Kështu brenda funksionit mund t'i përdorësh metodat e atij trait-i.
EnglishEN
With T: Display or where T: Clone you constrain a generic: “any type, as long as it can do this”. Then inside the function you can use that trait's methods.
Si ta mendosh
Si rregulli „çdo lojtar, mjafton të ketë këpucë futbolli“.
Lexoje në anglisht
Like the rule “any player, as long as they have football boots”.
Shembull kodirust
fn shfaq_te_gjitha<T>(v: &[T]) where T: std::fmt::Display {
for x in v { println!("{x}"); }
}