Checking my understanding of reading docs

I want to make sure I'm reading the docs correctly in order to determine the types that implement a given trait. For example, looking at std::borrow::ToOwned - Rust I think it is telling me that it is implemented by str, Str, OsStr, Path, any array whose items implement Clone, and any type that implements Clone. Am I reading that correctly?

[T] is a slice and not an array ([T; n]), but putting that aside, yes you're reading that correctly.

Note 1: But you can get a slice from an array anyway.

Note 2: I don't know why they're not showing up in the list of implementors, but arrays implement Clone and some other traits too, as described in the link above. Probably something to do with how it's implemented and the recent advancement of const generics.

1 Like

I see this in the docs for std::borrow::Borrow:

impl<T> Borrow<T> for T where
T: ?[Sized]

Does this mean that all the built-in scalar types implement Borrow, including slices and tuples of those types?

It's broader than that. It means that all types implement Borrow<Self>, regardless of how complicated they are or where they're defined. It doesn't mean, however, that all containers automatically get a borrow implementation for their contents.

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.