Implicitly convert &str to [u8] for compatibility with existing usage code

Thanks to stephaneyfx from the #rust IRC channel for showing me that
this needs separate type parameters on the functions in order to
compile.

The only API change that can't be helped are the `line_junk` and
`char_junk` function pointers in the Differ struct, which now take
`&&str` and `&char` parameters, respectively. This is probably for the
better, since `char_junk` now operates on Unicode scalar values rather
than the single UTF-8 bytes disguised as `&str` that were previously
retrieved via the unsafe `slice_unchecked()` function.
This commit is contained in:
nmlgc
2018-07-05 21:46:43 +02:00
parent 6fd59b0c08
commit 06afc1879b
5 changed files with 33 additions and 19 deletions
+4 -4
View File
@@ -5,7 +5,7 @@ use difflib::sequencematcher::{Match, Opcode, SequenceMatcher};
#[test]
fn test_longest_match() {
let matcher = SequenceMatcher::new(b" abcd", b"abcd abcd");
let matcher = SequenceMatcher::new(" abcd", "abcd abcd");
let m = matcher.find_longest_match(0, 5, 0, 9);
assert_eq!(m.first_start, 0);
assert_eq!(m.second_start, 4);
@@ -14,7 +14,7 @@ fn test_longest_match() {
#[test]
fn test_all_matches() {
let mut matcher = SequenceMatcher::new(b"abxcd", b"abcd");
let mut matcher = SequenceMatcher::new("abxcd", "abcd");
let result = matcher.get_matching_blocks();
let mut expected_result = Vec::new();
expected_result.push(Match {
@@ -37,7 +37,7 @@ fn test_all_matches() {
#[test]
fn test_get_opcodes() {
let mut matcher = SequenceMatcher::new(b"qabxcd", b"abycdf");
let mut matcher = SequenceMatcher::new("qabxcd", "abycdf");
let result = matcher.get_opcodes();
let mut expected_result = Vec::new();
expected_result.push(Opcode {
@@ -80,7 +80,7 @@ fn test_get_opcodes() {
#[test]
fn test_ratio() {
let mut matcher = SequenceMatcher::new(b"abcd", b"bcde");
let mut matcher = SequenceMatcher::new("abcd", "bcde");
assert_eq!(matcher.ratio(), 0.75);
}