If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.
Phoronix, Linux Hardware Reviews, Linux hardware benchmarks, Linux server benchmarks, Linux benchmarking, Desktop Linux, Linux performance, Open Source graphics, Linux How To, Ubuntu benchmarks, Ubuntu hardware, Phoronix Test Suite
Support for specializations is pretty good news. There was, for example, three ways of turning a &str into a String:
let string = var.to_string();
let string = var.to_owned();
let string = String::from(var);
The first is a generic method supported by all types that's not at all optimized. It's the equivalent of running let string = format!("{}", var);. This is useful for converting numbers and structures into strings, but it's redundant to format a string as a string. The second and third options are identical to each other and are optimized because they are simply creating an owned string from a string reference.
With the new release providing support for specialization, to_string() is now equivalent to to_owned() so programmers don't have to know the difference anymore. Any use of to_string() performed on an &str will automatically be optimized to to_owned() so that there is no performance impact in choosing to_string() instead of to_owned() or String::from().
Support for specializations is pretty good news. There was, for example, three ways of turning a &str into a String:
let string = var.to_string();
let string = var.to_owned();
let string = String::from(var);
The first is a generic method supported by all types that's not at all optimized. It's the equivalent of running let string = format!("{}", var);. This is useful for converting numbers and structures into strings, but it's redundant to format a string as a string. The second and third options are identical to each other and are optimized because they are simply creating an owned string from a string reference.
With the new release providing support for specialization, to_string() is now equivalent to to_owned() so programmers don't have to know the difference anymore. Any use of to_string() performed on an &str will automatically be optimized to to_owned().
I think you may have alienated any readers who do not know Rust already. Then again, who else reads this article …
I think you may have alienated any readers who do not know Rust already. Then again, who else reads this article …
I would imagine that anyone with a rudimentary understanding of systems programming would at least get the gist of the subject, even if they do not know Rust yet. Most programming languages have a format function, such as C's sprintf function. Rust's format!() macro works similarly, only it is both faster and simpler to use. A C programmer would also know the difference between an owned value and a reference, although the concept of vectors is beyond the scope of C.
Comment