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

Main example for HashSet. #15667

Merged
merged 1 commit into from Jul 16, 2014

Conversation

Projects
None yet
3 participants
@treeman
Copy link
Contributor

treeman commented Jul 14, 2014

Example code for HashSet, similar to the HashMap example.

bors added a commit that referenced this pull request Jul 16, 2014

@treeman

This comment has been minimized.

Copy link
Contributor Author

treeman commented Jul 16, 2014

@alexcrichton It appears I have accidentally pushed up some more documentation changes to this pull request instead of creating a new. Shall I create a new one or roll with this?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 16, 2014

That's ok, I'll take a peek

@@ -689,7 +689,7 @@ impl DefaultResizePolicy {
/// 3. Emmanuel Goossaert. ["Robin Hood hashing: backward shift
/// deletion"](http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/)
///
/// # Example
/// ## Example

This comment has been minimized.

@alexcrichton

alexcrichton Jul 16, 2014

Member

The predominant style in the rest of the documentation is to use one hash mark, why change to two?

/// # use std::collections::HashSet;
/// let mut set = HashSet::new();
/// set.insert("a".to_string());
/// set.insert("b".to_string());

This comment has been minimized.

@alexcrichton

alexcrichton Jul 16, 2014

Member

You may even be able to elide the .to_string() here

/// // Will print in an arbitrary order.
/// for x in set.move_iter() {
/// // s has type String, not &String.
/// println!("{}", x);

This comment has been minimized.

@alexcrichton

alexcrichton Jul 16, 2014

Member

You may want to do something which requires ownership of the value rather than printing it, perhaps collecting into a Vec<String>?

This comment has been minimized.

@alexcrichton

alexcrichton Jul 16, 2014

Member

The comment also refers to s but it looks like the variable is x

/// let diff: HashSet<int> = a.difference(&b).map(|&x| x).collect();
/// assert_eq!(diff, vec!(1i).move_iter().collect());
///
/// // Not that difference is not symmetric,

This comment has been minimized.

@alexcrichton

alexcrichton Jul 16, 2014

Member

Not => Note

/// // Not that difference is not symmetric,
/// // and `b - a` means something else:
/// let diff: HashSet<int> = b.difference(&a).map(|&x| x).collect();
/// assert_eq!(diff, vec!(4i).move_iter().collect());

This comment has been minimized.

@alexcrichton

alexcrichton Jul 16, 2014

Member

We predominately try to use vec![...] for vector literals.

This comment has been minimized.

@treeman

treeman Jul 16, 2014

Author Contributor

I see. It was a bit cumbersome to convert a fixed size list to set, it would have been nice to either have a .move_iter() or a vec! like construct. It wasn't nice to use two different approaches though.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 16, 2014

Thanks for all the new examples!

@treeman

This comment has been minimized.

Copy link
Contributor Author

treeman commented Jul 16, 2014

Thanks for the pointers.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 16, 2014

Looks good to me! Could you squash the commits into one with a description about what documentation was added?

Extend HashSet documentation.
Add main example and simple examples for the methods.
@treeman

This comment has been minimized.

Copy link
Contributor Author

treeman commented Jul 16, 2014

Done.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented on 80ef6b8 Jul 16, 2014

This comment has been minimized.

Copy link
Contributor

bors replied Jul 16, 2014

merging treeman/rust/set-doc = 80ef6b8 into auto

This comment has been minimized.

Copy link
Contributor

bors replied Jul 16, 2014

treeman/rust/set-doc = 80ef6b8 merged ok, testing candidate = 06c7ee9

This comment has been minimized.

Copy link
Contributor

bors replied Jul 16, 2014

fast-forwarding master to auto = 06c7ee9

bors added a commit that referenced this pull request Jul 16, 2014

@bors bors closed this Jul 16, 2014

@bors bors merged commit 80ef6b8 into rust-lang:master Jul 16, 2014

1 of 2 checks passed

continuous-integration/travis-ci The Travis CI build could not complete due to an error
Details
default all tests passed

@treeman treeman deleted the treeman:set-doc branch Jul 20, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.