title: How do I write a trait method that knows the implementor is [u8]?
body: <p>I'm implementing a trait for <code>&amp;[u8]</code> but I cannot use <code>self</code> in the trait implementation. I assume that the trait can not detect the type and I should use a <code>where</code> clause, but I don't know how can I use it without an implementor.</p>
  
  <pre><code>use std::fmt::Debug;
  
  pub trait Xor: Debug {
      fn xor(&amp;self, key_bytes: &amp;[u8]) -&gt; &amp;[u8] {
          for n in &amp;self[..] {
              dbg!(n);
          }
          unimplemented!()
      }
  }
  
  impl Xor for [u8] {}
  
  fn main() {
      let xa = b"1234";
      xa.xor(b"123");
  }
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=ece590b3cd3ed65f3a840d013ce8a00e" rel="nofollow noreferrer">Playground</a></p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0608]: cannot index into a value of type `&amp;Self`
   --&gt; src/main.rs:5:19
    |
  5 |         for n in &amp;self[..] {
    |                   ^^^^^^^^
  </code></pre>