Open XAMPPRocky opened 7 years ago
You could do .find(predicate).next()
. Or is that what you mean by "a bit of boilerplate"?
The boilerplate is not so much in the number of characters as document.find_one(pred).unwrap()
is close to document.find(pred).next().unwrap()
it's more the boilerplate of only returning collection types, especially when a lot of them could be single element collections.
Actually, it's not quite the same. I think find_one()
should return None
if there are two or more nodes in the selection, too.
@HighCommander4 I don't think that is intuitive. I've never found myself commonly needing to require that a query result is completely unique. This would be a lot easier to convey through document.find(pred).size_hint()
/document.find(pred).collect::<Vec<_>>().len() == 1
If it shouldn't be unique, shouldn't it be called find_first
instead?
Currently just to find a single element requires a bit of boilerplate. Consider adding a a
find_one
method that returnsOption<Node>
.