-
Notifications
You must be signed in to change notification settings - Fork 5
Rusty things
This page contains some useful information about Rust.
cargo test -- --nocapture matcher::trie::node::node::given_empty_trie_when_literals_are_inserted_then_they_can_be_looked_up
You can do this by destructoring it via a let
binding. The destructoring
function (like split()
) takes self
, not a reference. Then it can destructor
it.
You can extend a lifetime with the following syntax:
struct LiteralLookupHit<'a, 'b: 'a, 'c>(&'a mut Node<'b>, &'c str);
Check your lifetimes. If there is one on self
it can cause problems. If a trait
doesn't need a litetime just one of its methods, then place the lifetime on the method
and not on the trait.
Use case: You have a trait (HasOptionalParameter
) which should be implemented
by all Parser
implementations. At first they would be the same, so you decide
to implement HasOptionalParameter
for Parser
(impl HasOptionalParameter for Parser
).
With this approach you can get weird compiler errors (type X does not implement any method in scope named Y
, but the trait is in scope...).
The solution is to implement HasOptionalParameter
for every type which implements Parser
:
impl<T> HasOptionalParameter for T where T:Parser { ... }