What about more traits?

What about adding more traits to Rust to make it more standart for structs that share the same methods ?

for examples:

  • len()
  • contains()
  • startswith()
  • endswith()
  • strip_prefix()
  • ...

that would allow for functions that could take any arguments (&str, String, Vec, ...)
making it easier to work with some specific needs and add standardization avoiding people to use alternate names

Rust mostly solves this by having Deref which allows other string-like types to automatically expose a &str slice that works with all these methods. You can also use AsRef<str> in generic contexts.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.