Closed vkurilin closed 2 months ago
It's so TrieCommon
can be implemented on &
and &mut
types. I forget the details, but this was to make lifetimes play nicely.
You shouldn't need to clone anything to call .key()
on SubTrie
, because the TrieCommon
trait is implemented on &SubTrie
:
https://docs.rs/radix_trie/latest/radix_trie/trait.TrieCommon.html#implementors
I tried adding your code example to examples/debug.rs
and it works without issue:
if let Some(ancestor) = trie.get_ancestor("hello world") {
if ancestor.key() == Some(&"hello") {
println!("{:?}", ancestor.value());
}
}
Can you elaborate on the error you hit?
Hmm, looks like I jumped to conclusions.
In a large project with a complex type, I encountered the error "rust value used after move," on this line, saw self in the trait, and thought — here it is 🙈
In a clean example, it indeed does not reproduce.
I tested it with primitive types and defined my own non-copy type with custom Eq
.
Everything works as expected; this issue can be closed.
Thank you so much for such a quick response!
Hello!
Is there a specific reason why most access methods in
SubTrie
consumeself
rather than taking it by a constant reference?For example, it seems that
key()
andvalue()
fromTrieCommon
could take&self
, which would enable code like this:This change would allow us to avoid the need to create temporary variables or clones, potentially improving both performance and readability. Could you please provide some insight into this design choice?
Thank you!