misc/process/wait.html)
    9. [ **20.6.** Filesystem Operations ](../std_misc/fs.html)
    10. [ **20.7.** Program arguments ](../std_misc/arg.html) â± 
    11.       1. [ **20.7.1.** Argument parsing ](../std_misc/arg/matching.html)
    12. [ **20.8.** Foreign Function Interface ](../std_misc/ffi.html)
  41. [ **21.** Testing ](../testing.html) â± 
  42.     1. [ **21.1.** Unit testing ](../testing/unit_testing.html)
    2. [ **21.2.** Documentation testing ](../testing/doc_testing.html)
    3. [ **21.3.** Integration testing ](../testing/integration_testing.html)
    4. [ **21.4.** Dev-dependencies ](../testing/dev_dependencies.html)
  43. [ **22.** Unsafe Operations ](../unsafe.html) â± 
  44.     1. [ **22.1.** Inline assembly ](../unsafe/asm.html)
  45. [ **23.** Compatibility ](../compatibility.html) â± 
  46.     1. [ **23.1.** Raw identifiers ](../compatibility/raw_identifiers.html)
  47. [ **24.** Meta ](../meta.html) â± 
  48.     1. [ **24.1.** Documentation ](../meta/doc.html)
    2. [ **24.2.** Playground ](../meta/playground.html)

__ __

  * Light (default) 
  * Rust 
  * Coal 
  * Navy 
  * Ayu 

__

#  Rust By Example

[ __ ](../print.html "Print this book") [ __ ](https://github.com/rust-
lang/rust-by-example "Git repository") [ __ ](https://github.com/rust-
lang/rust-by-example/edit/master/src/trait/disambiguating.md "Suggest an
edit")

#  Disambiguating overlapping traits

A type can implement many different traits. What if two traits both require
the same name? For example, many traits might have a method named ` get() ` .
They might even have different return types!

Good news: because each trait implementation gets its own ` impl ` block, it's
clear which trait's ` get ` method you're implementing.

What about when it comes time to _call_ those methods? To disambiguate between
them, we have to use Fully Qualified Syntax.

    
    
    trait UsernameWidget {
        // Get the selected username out of this widget
        fn get(&self) -> String;
    }
    
    trait AgeWidget {
        // Get the selected age out of this widget
        fn get(&self) -> u8;
    }
    
    // A form with both a UsernameWidget and an AgeWidget
    struct Form {
        username: String,
        age: u8,
    }
    
    impl UsernameWidget for Form {
        fn get(&self) -> String {
            self.username.clone()
        }
    }
    
    impl AgeWidget for Form {
        fn get(&self) -> u8 {
            self.age
        }
    }
    
    fn main() {
        let form = Form {
            username: "rustacean".to_owned(),
            age: 28,
        };
    
        // If you uncomment this line, you'll get an error saying
        // "multiple `get` found". Because, after all, there are multiple methods
        // named `get`.
        // println!("{}", form.get());
    
        let username = <Form as UsernameWidget>::get(&form);
        assert_eq!("rustacean".to_owned(), username);
        let age = <Form as AgeWidget>::get(&form);
        assert_eq!(28, age);
    }
    

###  See also:

[ The Rust Programming Language chapter on Fully Qualified syntax
](https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#fully-qualified-
syntax-for-disambiguation-calling-methods-with-the-same-name)

[ __ ](../trait/supertraits.html "Previous chapter") [ __ ](../macros.html
"Next chapter")

[ __ ](../trait/supertraits.html "Previous chapter") [ __ ](../macros.html
"Next chapter")