title: Is it possible for the assert_eq macro to show a diff when two strings aren't equal?
body: <p>I'm writing some tests for a language tokenizer and I'm comparing a JSON-serialized version of the tokenization produced by the tokenizer with a serialization of a known-good tokenization.  So I have some tests like this:</p>
  
  <pre class="lang-rust prettyprint-override"><code>#[test]
  fn test_tokenize() {
      let actual_token_json = /* string */;
      let expected_token_json = /* string */;
  
      assert_eq!(actual_token_json, expected_token_json);
  }
  </code></pre>
  
  <p>However, when those tests fail, <code>cargo test</code> just says that the JSON strings weren't equal and prints them both out, which isn't that useful.  Since the JSON strings are both pretty-printed, it would be more helpful if <code>cargo test</code> printed out a line diff of the two strings.  Is there any way I could do this?</p>
  
  <p><strong><em>Update</em></strong>:
  Someone edited the title of this post but deleted an important piece of information: I'm looking for a <em>line</em> diff when <em>two strings</em> aren't equal.  One of the answers I'm seeing here is for the more general question of getting a <em>line <strong>and</strong> character</em> diff of the debug representations of two values when they're not equal.  That's either more than I need or not what I need.  For example, the diff of the debug representations of two strings won't give me a line diff but a large, convoluted character diff (since the lines show up in the debug representation as escaped "\n" tokens).</p>