The way the FromStr
trait is defined, you cannot produce a result which borrows from the input, because FromStr::from_str()
always uses an input lifetime unrelated to Self
. Your choices are:
- Don't make
Cedict
borrow the input string, but own each piece (useString
instead of&'a str
). This also means that theCedict
is allowed to outlive the input, which might be desirable — right now, you're going to have to use theCedict
only within the stack frame that created it. - Don't use
FromStr
; just write your own function inimpl Cedict {}
. Then you're free to design the signature as you need it. (Or if you really want a trait, implementTryFrom<&'a str>
.)
Another recent thread on the same problem: