book icon indicating copy to clipboard operation
book copied to clipboard

Chapter 8: ways to initialize new Vector and String

Open syaltamimi opened this issue 3 years ago • 0 comments

Vectors and Strings were discussed in parallel in Chapter 8. This thread aims at improving the completeness and consistency of the presented materials.

Current flow of ideas:

  1. Vector: [Section 8.1]
    • Create a new vector using Vec::new()
    • Create a new vector with initial value using a) vec!
  2. String: [Section 8.2]
    • Create a new string using String::new()
    • Create a new string with initial value using: a) to_string() b) String::from()

Suggested flow of ideas:

  1. Vector: [Section 8.1]
    • Create a new vector using Vec::new()
    • Create a new vector with initial value using: a) Vec::from() b) vec!
  2. String: [Section 8.2]
    • Create a new string using String::new()
    • Create a new string with initial value using: a) String::from() b) " ".to_string()

The rational behind this modification is:

  • Vec::from() is analogous to String::from() and has been supported since version 1.44.
  • It might be better to introduce String::from() first because
    • it belongs to the String type as opposed to to_string which belongs to the other types such as str
    • plus String:from() was used in previous chapters

syaltamimi avatar Aug 24 '22 06:08 syaltamimi