Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation on String's methods #30148

Merged
merged 1 commit into from
Dec 11, 2015

Conversation

steveklabnik
Copy link
Member

Part of #29376

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

/// assert_eq!(String::from_utf16(v).unwrap(),
/// "𝄞music".to_string());
/// assert_eq!(Some(String::from("𝄞music")),
/// String::from_utf16(v));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come these assertions were swapped? I think it's generally assert(actual, expected) in terms of error messages at least.

I also think that String::from may be a bit distracting here when compared to to_string?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe .to_owned would work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think that String::from may be a bit distracting here when compared to to_string?

I happen to like it more in this case, as it's closely named with from_utf16.

@tbu- this isn't generic code, so .to_owned isn't appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't write this test in this way anyway, as FromUtf16Error doesn't implement PartialEq, ugh

@steveklabnik
Copy link
Member Author

Various fixups sent!

/// ```
/// let mut s = "foo".to_string();
/// let mut s = String::from("foo");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how this aligns better in the from_utf16 example above, but this documentation is setting an example of how to create strings in the wild. In general although String::from is possible I would say the more idiomatic way to do this is foo.to_string(), so it seems a little odd to me that all these examples are switching to String::from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, they're split across a lot of ways. We really need to decide what the actual convention is, there's a lot of documentation that will end up changing no matter what is chosen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but at some point this is what's setting that convention regardless of whatever future conversations are had. It seems easier to just have less churn and not change what's there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Since I'm going through a sweep of std in whole, I've been trying to just do the work individually, as it's easier. Same goes for the assert order issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah to clarify I mean leave what's here in terms of "foo".to_string()

@alexcrichton
Copy link
Member

@bors: r+ 97455b258fddc72942cb6dad587d8bee1c660327

Talked in person and concluded that it's probably best to land better docs for now and we can shake out conventions all at once or keep riding this train!

@bors
Copy link
Contributor

bors commented Dec 10, 2015

🔒 Merge conflict

@bors
Copy link
Contributor

bors commented Dec 10, 2015

☔ The latest upstream changes (presumably #30182) made this pull request unmergeable. Please resolve the merge conflicts.

@steveklabnik
Copy link
Member Author

@bors: r=alexcrichton

@bors
Copy link
Contributor

bors commented Dec 10, 2015

📌 Commit 072dd6f has been approved by alexcrichton

bors added a commit that referenced this pull request Dec 10, 2015
@bors
Copy link
Contributor

bors commented Dec 10, 2015

⌛ Testing commit 072dd6f with merge 0d36840...

@bors bors merged commit 072dd6f into rust-lang:master Dec 11, 2015
@steveklabnik steveklabnik deleted the doc_string branch June 19, 2016 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants