What is the fastest correct way to detect that there are no duplicates in a JSON array?
问题 I need to check if all items are unique in an array of serde_json::Value . Since this type does not implement Hash I came up with the following solution: use serde_json::{json, Value}; use std::collections::HashSet; fn is_unique(items: &[Value]) -> bool { let mut seen = HashSet::with_capacity(items.len()); for item in items.iter() { if !seen.insert(item.to_string()) { return false; } } true } fn main() { let value1 = json!([1, 2]); assert!(is_unique(&value1.as_array().unwrap())); let value2 =