# \`ToOwned\` is a bad name for the trait

**URL:** <https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129>\
**Category:** Uncategorized\
**Created:** [January 7, 2025, 4:08pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129 "2025-01-07T16:08:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvcmarcenes](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jvcmarcenes/32/11971_2.png) [@jvcmarcenes](https://internals.rust-lang.org/u/jvcmarcenes)\
**Post date:** [January 7, 2025, 4:08pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/1 "2025-01-07T16:08:14Z")

</div>

For the same reason that `Borrow` and `Clone` aren't `ToBorrow` and `ToCloned`.

It should just be `Own`

then, you could create strings with `"my static str".own()`, and nobody would complain about "to\_owned" or "to\_string" anymore too

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [January 7, 2025, 4:10pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/2 "2025-01-07T16:10:44Z")

</div>

Are you familiar with the existing conventions around `to_`, `as_`, `into_`?

> **[Naming - Rust API Guidelines](https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv)**
>
> This is a set of recommendations on how to design and present APIs for the Rust programming language.

In that framework, `to_` is the correct naming choice.

---

<div class="post-metadata">

**Author:** ![jvcmarcenes](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jvcmarcenes/32/11971_2.png) [@jvcmarcenes](https://internals.rust-lang.org/u/jvcmarcenes)\
**Post date:** [January 7, 2025, 4:23pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/3 "2025-01-07T16:23:35Z")

</div>

By that logic `Clone` should be `ToCloned` and `Borrow` should be `AsBorrowed`, no?

What I'm saying is that regardless of these conventions, `ToOwned::to_owned` has unnecessary morphology that could just as easily be conveyed with `Own::own`

It follows the logic of the `Clone` naming. The trait is a verb that you can do to a value.

I think that `as_`, `to_`, and `into_` are useful when converting between different types, such as `IntoIterator` (but even then, why not `Iterate`, `vec.iterate()`). But it especially doesn't make sense when converting between representations of the same type

---

<div class="post-metadata">

**Author:** ![jvcmarcenes](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jvcmarcenes/32/11971_2.png) [@jvcmarcenes](https://internals.rust-lang.org/u/jvcmarcenes)\
**Post date:** [January 7, 2025, 4:24pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/4 "2025-01-07T16:24:46Z")

</div>

And I want to reinforce that I'd **much** rather write `"whatever".own()` than `"whatever".to_owned()`

---

<div class="post-metadata">

**Author:** ![burntsushi](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/burntsushi/32/279_2.png) [@burntsushi](https://internals.rust-lang.org/u/burntsushi)\
**Post date:** [January 7, 2025, 4:35pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/5 "2025-01-07T16:35:39Z")

</div>

Do you have a specific outcome you'd like to see here? Or are you venting?

---

<div class="post-metadata">

**Author:** ![jvcmarcenes](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jvcmarcenes/32/11971_2.png) [@jvcmarcenes](https://internals.rust-lang.org/u/jvcmarcenes)\
**Post date:** [January 7, 2025, 5:04pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/6 "2025-01-07T17:04:42Z")

</div>

Ah, I'm venting about naming. I doubt such a refactor would ever get merged. I just wanted to see if anyone had similar thoughts, guess it's just me.

---

<div class="post-metadata">

**Author:** ![SkiFire13](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/skifire13/32/7579_2.png) [@SkiFire13](https://internals.rust-lang.org/u/SkiFire13)\
**Post date:** [January 7, 2025, 6:09pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/7 "2025-01-07T18:09:44Z")

</div>

> [@jvcmarcenes](#):
>
> then, you could create strings with `"my static str".own()`, and nobody would complain about "to\_owned" or "to\_string" anymore too

Isn't the problem with `to_owned` and `to_string` the fact that they are two ways to do the same thing? (3 if you count `into`, 4 with `clone` if you're "converting" a `&String` to a `String`)

If `to_owned` was named `own` this situation would remain the same.

---

<div class="post-metadata">

**Author:** ![bjorn3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bjorn3/32/2736_2.png) [@bjorn3](https://internals.rust-lang.org/u/bjorn3)\
**Post date:** [January 7, 2025, 6:39pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/8 "2025-01-07T18:39:30Z")

</div>

> [@SkiFire13](#):
>
> Isn't the problem with `to_owned` and `to_string` the fact that they are two ways to do the same thing?

They are only the same thing for strings. For non-string types to\_string would convert it to a string, while to\_owned would create an owned non-string value.

---

<div class="post-metadata">

**Author:** ![HjVT](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hjvt/32/10365_2.png) [@HjVT](https://internals.rust-lang.org/u/HjVT)\
**Post date:** [January 7, 2025, 6:39pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/9 "2025-01-07T18:39:39Z")

</div>

No? Neither `clone` nor `borrow` consume `self`.  
If anything, `clone` and `borrow` fit with a different naming pattern: `as_Y(&X)`.

---

<div class="post-metadata">

**Author:** ![dlight](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dlight/32/8462_2.png) [@dlight](https://internals.rust-lang.org/u/dlight)\
**Post date:** [January 7, 2025, 8:52pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/10 "2025-01-07T20:52:34Z")

</div>

But "as" in Rust is used for cheap, trivial conversions from a borrowed type into another borrowed type, like [`AsRef`](https://doc.rust-lang.org/std/convert/trait.AsRef.html), as in the already linked API guideline ([Naming - Rust API Guidelines](https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv))

`Clone` is really a "to" operation in the sense conveyed by the table in the guideline (borrowed -\> owned, expensive). It could indeed be called `ToClone`, like `Borrow` could be called `AsBorrow`

---

<div class="post-metadata">

**Author:** ![glandium](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@glandium](https://internals.rust-lang.org/u/glandium)\
**Post date:** [January 7, 2025, 10:59pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/11 "2025-01-07T22:59:39Z")

</div>

> [@bjorn3](#):
>
> They are only the same thing for strings.

I was going to say they aren't the same thing, but as I was writing a test case showing that, it turned out they are. And the reason is far from obvious to the casual reader because the documentation is misleading, unfortunately. It only shows `impl<T> ToString for T where T: Display + ?Sized`, and hides the fact that there are many specializations, one of which is for `&str`, where the implementation ... [uses `to_owned`](https://github.com/rust-lang/rust/blob/1.83.0/library/alloc/src/string.rs#L2826-L2831). If rustdoc ignores specializations, at least the text should probably say something about these.

---

<div class="post-metadata">

**Author:** ![pitaj](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pitaj/32/11262_2.png) [@pitaj](https://internals.rust-lang.org/u/pitaj)\
**Post date:** [January 7, 2025, 11:17pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/12 "2025-01-07T23:17:52Z")

</div>

The specializations are not intended to be covered by the stability guarantees of the standard library, which is why they are not documented as such. Stabilization (even `min_specialization`) is still an unstable feature.

---

<div class="post-metadata">

**Author:** ![glandium](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@glandium](https://internals.rust-lang.org/u/glandium)\
**Post date:** [January 7, 2025, 11:37pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/13 "2025-01-07T23:37:04Z")

</div>

Sure, but the fact that to\_string is explicitly _not_ using Display for strings is an important detail that should be highlighted somewhere. I was actually avoiding to\_string on string slices because I thought it was using Display.

---

<div class="post-metadata">

**Author:** ![chrefr](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chrefr](https://internals.rust-lang.org/u/chrefr)\
**Post date:** [January 7, 2025, 11:53pm UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/14 "2025-01-07T23:53:56Z")

</div>

Why does it matter how is it being written?

---

<div class="post-metadata">

**Author:** ![glandium](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@glandium](https://internals.rust-lang.org/u/glandium)\
**Post date:** [January 8, 2025, 12:05am UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/15 "2025-01-08T00:05:28Z")

</div>

Using Display has significantly more overhead. [Compiler Explorer](https://rust.godbolt.org/z/1PbKccTqr)

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/quinedot/32/7294_2.png) [@quinedot](https://internals.rust-lang.org/u/quinedot)\
**Post date:** [January 8, 2025, 12:09am UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/16 "2025-01-08T00:09:18Z")

</div>

> [@glandium](#):
>
> Sure, but the fact that to\_string is explicitly _not_ using Display for strings is an important detail that should be highlighted somewhere. I was actually avoiding to\_string on string slices because I thought it was using Display.

> [@chrefr](#):
>
> Why does it matter how is it being written?

"Don't use `to_string`, use `to_owned` instead" [was a common correction before the specialization.](https://internals.rust-lang.org/t/pre-acp-un-specialize-impl-tostring/20549/15)

---

<div class="post-metadata">

**Author:** ![jvcmarcenes](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jvcmarcenes/32/11971_2.png) [@jvcmarcenes](https://internals.rust-lang.org/u/jvcmarcenes)\
**Post date:** [January 8, 2025, 12:12am UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/17 "2025-01-08T00:12:26Z")

</div>

My thinking is that `to_owned` is the best current alternative. `static_string.to_string()` is silly, `to_owned` shows you're creating an owned type from a borrowed one

If it was shorter, it would probably be more likely to be used, and it would be easier to argue it is better than `to_string`. it could become the canonical way to get a String from a &str

---

<div class="post-metadata">

**Author:** ![jvcmarcenes](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jvcmarcenes/32/11971_2.png) [@jvcmarcenes](https://internals.rust-lang.org/u/jvcmarcenes)\
**Post date:** [January 8, 2025, 12:12am UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/18 "2025-01-08T00:12:53Z")

</div>

neither does ToOwned consume self

---

<div class="post-metadata">

**Author:** ![jvcmarcenes](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jvcmarcenes/32/11971_2.png) [@jvcmarcenes](https://internals.rust-lang.org/u/jvcmarcenes)\
**Post date:** [January 8, 2025, 12:14am UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/19 "2025-01-08T00:14:39Z")

</div>

My point is that `ToCloned` and `AsBorrowed` are dumb names. The concept is just as easily, if not better, conveyed by just `Clone` and `Borrow`

using verbs for single-function traits seems like the best way to go about this. the function should be the verb that's happening to the value

Of course this isn't always possible, but having to prefix things with `To` because of "convention" is as dumb as prefixing interfaces with `I`

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [January 8, 2025, 12:40am UTC](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129/20 "2025-01-08T00:40:34Z")

</div>

> [@jvcmarcenes](#):
>
> My thinking is that `to_owned` is the best current alternative

You might find these URLO posts interesting:

> **[\`to\_string()\` vs \`to\_owned()\` for string literals](https://users.rust-lang.org/t/to-string-vs-to-owned-for-string-literals/1441/6?u=scottmcm)**
>
> I found that my opinion on this has changed significantly over the past 12 months as I have grown more experienced with Rust. I now strongly prefer to\_owned() for string literals over either of to\_string() or into(). What is the difference...

> **[Current guidance on &str to String (to\_owned vs to\_string)](https://users.rust-lang.org/t/current-guidance-on-str-to-string-to-owned-vs-to-string/75754/7?u=scottmcm)**
>
> Some of the 2015 guidance is out of date, but I don't think anything's changed substantially in the last few years here. I still like this post from 2017 about it: Here're some other previous conversations: What is the idiomatic way to...

[Next page](https://internals.rust-lang.org/t/toowned-is-a-bad-name-for-the-trait/22129.md?page=2)
