pretzelhammer / rust-blog

Educational blog posts for Rust beginners
Apache License 2.0
7.53k stars 396 forks source link

(nit) Update description of example provided to explain the Clone trait. #45

Closed sateeshkumarb closed 3 years ago

sateeshkumarb commented 3 years ago

In the section on Clone the description for function _guaranteelength is as below:

Clone can also be useful in constructing instances of a type within a generic context. Here's an example from the previous section except using Clone instead of Default:

fn guarantee_length<T: Clone>(mut vec: Vec<T>, min_len: usize, fill_with: &T) -> Vec<T> {

But this function differs from the example in previous section in the method signature too as this takes an additional param fill_with. The signature of the function in section Default is as below:

fn guarantee_length<T: Default>(mut vec: Vec<T>, min_len: usize) -> Vec<T> {

Given this difference, I think the description for function _guranteelength in section Clone can be updated, as it differs from the previous example by taking an additional param. One way I can think of is:

Clone can also be useful in constructing instances of a type within a generic context. Here's the modified example from the previous section which makes use of Clone instead of Default:

P.S: Thank you for your excellent guides which provide a lucid explanation of many of the Rust concepts.

pretzelhammer commented 3 years ago

https://github.com/pretzelhammer/rust-blog/commit/0f257e3131e689349c4de56dc4b1ad1664e49def