Return a Result from constant_hash::probe.

When a hash table probe fails, return the index of the failed entry.
This can be used to store default values in the sentinel entries.
This commit is contained in:
Jakob Stoklund Olesen
2017-07-21 21:10:32 -07:00
parent 2b41f979cb
commit df1bf7d578
4 changed files with 38 additions and 22 deletions

View File

@@ -85,10 +85,10 @@ impl FromStr for Opcode {
}
match probe::<&str, [Option<Opcode>]>(&OPCODE_HASH_TABLE, s, simple_hash(s)) {
None => Err("Unknown opcode"),
Err(_) => Err("Unknown opcode"),
// We unwrap here because probe() should have ensured that the entry
// at this index is not None.
Some(i) => Ok(OPCODE_HASH_TABLE[i].unwrap()),
Ok(i) => Ok(OPCODE_HASH_TABLE[i].unwrap()),
}
}
}