Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a struct implement two traits with conflicting method names in Rust? [duplicate]

Tags:

rust

traits

Is it possible to implement two traits with conflicting method names in Rust? I know that it gives you a multiple applicable methods in scope error, but is there a way to resolve this? For example, some languages handle multiple inheritance by allowing you to explicitly specify which one method should take precedence

like image 218
Casebash Avatar asked Sep 20 '25 12:09

Casebash


1 Answers

You want Call expressions / Disambiguating Function Calls. The following are all equivalent:

let v = 32;
let _ = v.clone();
let _ = Clone::clone(&v);
let _ = <i32 as Clone>::clone(&v);
like image 60
DK. Avatar answered Sep 22 '25 06:09

DK.