<p dir="auto">This example uses <code class="notranslate">rust-crypto 0.2.14</code>. Failing to import the <code class="notranslate">Encryptor</code> trait that implements <code class="notranslate">encrypt</code> causes an unexpected error message. The trait isn't private and importing it compiles as expected.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="extern crate crypto;

use crypto::{ buffer, aes, blockmodes };
use crypto::buffer::{ ReadBuffer, WriteBuffer };

fn enc(key: &amp;[u8], iv: &amp;[u8], data: &amp;[u8]) {
    // Don't import the trait that implements encrypt()
    //use crypto::symmetriccipher::Encryptor;

    let mut encryptor = aes::cbc_encryptor(aes::KeySize::KeySize256,
                key, iv, blockmodes::PkcsPadding);

    let mut read_buffer = buffer::RefReadBuffer::new(data);
    let mut buffer = [0; 4096];
    let mut write_buffer = buffer::RefWriteBuffer::new(&amp;mut buffer);

    // Expected error: type `_` does not implement any method in scope named `encrypt`
    // Get error: source trait is private
    encryptor.encrypt(&amp;mut read_buffer, &amp;mut write_buffer, true);
}

fn main() {
}"><pre class="notranslate"><span class="pl-k">extern</span> <span class="pl-k">crate</span> crypto<span class="pl-kos">;</span>

<span class="pl-k">use</span> crypto<span class="pl-kos">::</span><span class="pl-kos">{</span> buffer<span class="pl-kos">,</span> aes<span class="pl-kos">,</span> blockmodes <span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-k">use</span> crypto<span class="pl-kos">::</span>buffer<span class="pl-kos">::</span><span class="pl-kos">{</span> <span class="pl-v">ReadBuffer</span><span class="pl-kos">,</span> <span class="pl-v">WriteBuffer</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>

<span class="pl-k">fn</span> <span class="pl-en">enc</span><span class="pl-kos">(</span><span class="pl-s1">key</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">iv</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">,</span> <span class="pl-s1">data</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-c">// Don't import the trait that implements encrypt()</span>
    <span class="pl-c">//use crypto::symmetriccipher::Encryptor;</span>

    <span class="pl-k">let</span> <span class="pl-k">mut</span> encryptor = aes<span class="pl-kos">::</span><span class="pl-en">cbc_encryptor</span><span class="pl-kos">(</span>aes<span class="pl-kos">::</span><span class="pl-smi">KeySize</span><span class="pl-kos">::</span><span class="pl-v">KeySize256</span><span class="pl-kos">,</span>
                key<span class="pl-kos">,</span> iv<span class="pl-kos">,</span> blockmodes<span class="pl-kos">::</span><span class="pl-v">PkcsPadding</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-k">let</span> <span class="pl-k">mut</span> read_buffer = buffer<span class="pl-kos">::</span><span class="pl-smi">RefReadBuffer</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>data<span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> buffer = <span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-c1">4096</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> write_buffer = buffer<span class="pl-kos">::</span><span class="pl-smi">RefWriteBuffer</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> buffer<span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-c">// Expected error: type `_` does not implement any method in scope named `encrypt`</span>
    <span class="pl-c">// Get error: source trait is private</span>
    encryptor<span class="pl-kos">.</span><span class="pl-en">encrypt</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> read_buffer<span class="pl-kos">,</span> <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> write_buffer<span class="pl-kos">,</span> <span class="pl-c1">true</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="src/main.rs:19:5: 19:65 error: source trait is private
src/main.rs:19     encryptor.encrypt(&amp;mut read_buffer, &amp;mut write_buffer, true);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"><pre class="notranslate"><code class="notranslate">src/main.rs:19:5: 19:65 error: source trait is private
src/main.rs:19     encryptor.encrypt(&amp;mut read_buffer, &amp;mut write_buffer, true);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</code></pre></div>
<p dir="auto"><code class="notranslate">rustc 1.0.0-nightly (706be5ba1 2015-02-05 23:14:28 +0000)</code></p>
<p dir="auto">My attempt to call <code class="notranslate">Any::get_type_id()</code> and use its return value of as an instance of <code class="notranslate">fmt::Debug</code> does not work without import of <code class="notranslate">std::any::TypeId</code> <em>struct</em>: <a href="http://doc.rust-lang.org/std/any/struct.TypeId.html" rel="nofollow">http://doc.rust-lang.org/std/any/struct.TypeId.html</a></p>
<p dir="auto">Example code:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="use std::thread;
// use std::any::TypeId; // uncomment this line to make the compile work

fn main() {
    let b1 = Box::new(3u64);
    println!(&quot;hello world, b1: {:?}&quot;, b1);
    let child = thread::Thread::scoped(|| {
        let b2 = Box::new(4u64);
        println!(&quot;other thread b2: {:?}&quot;, b2);
    });
    match child.join() {
        Ok(()) =&gt; {}
        Err(ref panic_arg) =&gt; {
            if let Some(s) = panic_arg.downcast_ref::&lt;&amp;str&gt;() {
                println!(&quot;whoops child died with str: {}&quot;, s);
            } else if let Some(s) = panic_arg.downcast_ref::&lt;String&gt;() {
                println!(&quot;whoops child died with String: {}&quot;, s);
            } else {
                let id = panic_arg.get_type_id();
                println!(&quot;whoops child died with unknown panic arg, id: {:?}&quot;, id);
            }
        }
    }
}"><pre class="notranslate"><span class="pl-k">use</span> std<span class="pl-kos">::</span>thread<span class="pl-kos">;</span>
<span class="pl-c">// use std::any::TypeId; // uncomment this line to make the compile work</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> b1 = <span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">3u64</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"hello world, b1: {:?}"</span>, b1<span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> child = thread<span class="pl-kos">::</span><span class="pl-smi">Thread</span><span class="pl-kos">::</span><span class="pl-en">scoped</span><span class="pl-kos">(</span>|| <span class="pl-kos">{</span>
        <span class="pl-k">let</span> b2 = <span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">4u64</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"other thread b2: {:?}"</span>, b2<span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-k">match</span> child<span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-v">Ok</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span> =&gt; <span class="pl-kos">{</span><span class="pl-kos">}</span>
        <span class="pl-v">Err</span><span class="pl-kos">(</span><span class="pl-k">ref</span> panic_arg<span class="pl-kos">)</span> =&gt; <span class="pl-kos">{</span>
            <span class="pl-k">if</span> <span class="pl-k">let</span> <span class="pl-v">Some</span><span class="pl-kos">(</span>s<span class="pl-kos">)</span> = panic_arg<span class="pl-kos">.</span><span class="pl-en">downcast_ref</span><span class="pl-kos">::</span><span class="pl-kos">&lt;</span><span class="pl-c1">&amp;</span><span class="pl-smi">str</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"whoops child died with str: {}"</span>, s<span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-k">if</span> <span class="pl-k">let</span> <span class="pl-v">Some</span><span class="pl-kos">(</span>s<span class="pl-kos">)</span> = panic_arg<span class="pl-kos">.</span><span class="pl-en">downcast_ref</span><span class="pl-kos">::</span><span class="pl-kos">&lt;</span><span class="pl-smi">String</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
                <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"whoops child died with String: {}"</span>, s<span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
                <span class="pl-k">let</span> id = panic_arg<span class="pl-kos">.</span><span class="pl-en">get_type_id</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"whoops child died with unknown panic arg, id: {:?}"</span>, id<span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Transcript of attempt to compile:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;anon&gt;:19:26: 19:49 error: source trait is private
&lt;anon&gt;:19                 let id = panic_arg.get_type_id();
                                   ^~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101"><pre class="notranslate"><code class="notranslate">&lt;anon&gt;:19:26: 19:49 error: source trait is private
&lt;anon&gt;:19                 let id = panic_arg.get_type_id();
                                   ^~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
</code></pre></div>