Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 0c2243f8a1696816431e7210e991fa52 > files > 1027

rust-doc-1.35.0-1.mga7.armv7hl.rpm

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <title>Universal Function Call Syntax</title>

    <link rel="stylesheet" type="text/css" href="../rust.css">

    <meta name="robots" content="noindex,follow">
<link rel="shortcut icon" href="https://www.rust-lang.org/favicon.ico">


</head>
<body class="rustdoc">
    <!--[if lte IE 8]>
    <div class="warning">
        This old browser is unsupported and will most likely display funky
        things.
    </div>
    <![endif]-->

    <div id="versioninfo">
  <img src="https://www.rust-lang.org/logos/rust-logo-32x32-blk.png" width="32" height="32" alt="Rust logo"><br>
  <span class="white-sticker"><a href="https://www.rust-lang.org">Rust</a> 1.35.0</span><br>
  <a href="https://github.com/rust-lang/rust/commit/"
    class="hash white-sticker"></a>
</div>


    <h1 class="title">Universal Function Call Syntax</h1>
    <p><small>There is a new edition of the book and this is an old link.</small></p>
<blockquote>
<p>Rust cannot prevent a trait from having a method with the same name as another trait’s method, nor can it prevent us from implementing both of these traits on one type.
In order to be able to call each of the methods with the same name, then, we need to tell Rust which one we want to use.</p>
</blockquote>

<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">trait</span> <span class="ident">Pilot</span> {
    <span class="kw">fn</span> <span class="ident">fly</span>(<span class="kw-2">&amp;</span><span class="self">self</span>);
}

<span class="kw">trait</span> <span class="ident">Wizard</span> {
    <span class="kw">fn</span> <span class="ident">fly</span>(<span class="kw-2">&amp;</span><span class="self">self</span>);
}

<span class="kw">struct</span> <span class="ident">Human</span>;

<span class="kw">impl</span> <span class="ident">Pilot</span> <span class="kw">for</span> <span class="ident">Human</span> {
}

<span class="kw">impl</span> <span class="ident">Wizard</span> <span class="kw">for</span> <span class="ident">Human</span> {
}

<span class="kw">impl</span> <span class="ident">Human</span> {
}

<span class="kw">fn</span> <span class="ident">main</span>() {
    <span class="kw">let</span> <span class="ident">person</span> <span class="op">=</span> <span class="ident">Human</span>;
    <span class="ident">Pilot</span>::<span class="ident">fly</span>(<span class="kw-2">&amp;</span><span class="ident">person</span>);
    <span class="ident">Wizard</span>::<span class="ident">fly</span>(<span class="kw-2">&amp;</span><span class="ident">person</span>);
    <span class="ident">person</span>.<span class="ident">fly</span>();
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Atrait%20Pilot%20%7B%0A%20%20%20%20fn%20fly(%26self)%3B%0A%7D%0A%0Atrait%20Wizard%20%7B%0A%20%20%20%20fn%20fly(%26self)%3B%0A%7D%0A%0Astruct%20Human%3B%0A%0Aimpl%20Pilot%20for%20Human%20%7B%0A%20%20%20%20fn%20fly(%26self)%20%7B%0A%20%20%20%20%20%20%20%20println!(%22This%20is%20your%20captain%20speaking.%22)%3B%0A%20%20%20%20%7D%0A%7D%0A%0Aimpl%20Wizard%20for%20Human%20%7B%0A%20%20%20%20fn%20fly(%26self)%20%7B%0A%20%20%20%20%20%20%20%20println!(%22Up!%22)%3B%0A%20%20%20%20%7D%0A%7D%0A%0Aimpl%20Human%20%7B%0A%20%20%20%20fn%20fly(%26self)%20%7B%0A%20%20%20%20%20%20%20%20println!(%22*waving%20arms%20furiously*%22)%3B%0A%20%20%20%20%7D%0A%7D%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20person%20%3D%20Human%3B%0A%20%20%20%20Pilot%3A%3Afly(%26person)%3B%0A%20%20%20%20Wizard%3A%3Afly(%26person)%3B%0A%20%20%20%20person.fly()%3B%0A%7D">Run</a></pre></div>
<hr />
<p>You can find the latest version of this information
<a href="ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name">here</a>.</p>

    <footer><p>
Copyright &copy; 2011 The Rust Project Developers. Licensed under the
<a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>
or the <a href="https://opensource.org/licenses/MIT">MIT license</a>, at your option.
</p><p>
This file may not be copied, modified, or distributed except according to those terms.
</p></footer>


</body>
</html>