<story><title>Rust lifetimes: Getting away with things that would be reckless in C++</title><url>http://www.randomhacks.net/2014/09/19/rust-lifetimes-reckless-cxx/</url></story><parent_chain></parent_chain><comment><author>missblit</author><text>In C++ if the string is a rvalue reference you could std::move it into part of the return value. Think a signature like&lt;p&gt;&lt;pre&gt;&lt;code&gt;    template&amp;lt;typename T&amp;gt;
    std::pair&amp;lt;std::string, std::vector&amp;lt;std::string_view&amp;gt;&amp;gt;
    tokenize_string(T &amp;amp;&amp;amp;str);
&lt;/code&gt;&lt;/pre&gt;
This would be efficient when the user passes a temporary, and it would be safe.&lt;p&gt;Which isn&amp;#x27;t to say the Rust solution isn&amp;#x27;t totally cool. Being able to easily check this class of errors at compile time is probably a lot nicer than needing to learn all the relatively complicated parts that would go into a easy to use &amp;#x2F; safe &amp;#x2F;efficient &amp;#x2F; still slightly weird C++ solution.</text></comment>
<story><title>Rust lifetimes: Getting away with things that would be reckless in C++</title><url>http://www.randomhacks.net/2014/09/19/rust-lifetimes-reckless-cxx/</url></story><parent_chain></parent_chain><comment><author>bsaul</author><text>Which makes me wonder :&lt;p&gt;1&amp;#x2F; could you build the same unsafe behiavor in Rust if you wanted to by not specifying lifetime constraints ?&lt;p&gt;2&amp;#x2F; If yes, shouldn&amp;#x27;t lifetime constraints be mandatory ?</text></comment>