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

Add RingBuf examples #15762

Merged
merged 1 commit into from
Jul 26, 2014
Merged

Add RingBuf examples #15762

merged 1 commit into from
Jul 26, 2014

Conversation

nham
Copy link
Contributor

@nham nham commented Jul 17, 2014

This adds examples for get(), get_mut(), swap(), iter() and mut_iter()

@alexcrichton
Copy link
Member

The imports for these examples seem fairly important, especially the import of Deque, could you un-hide the imports and change them to this?

use std::collections::{RingBuf, Deque};

@alexcrichton
Copy link
Member

Ah, I see @kballard pulled the other way in #15752, how confusing! Context is probably good enough.

Thanks!

@lilyball
Copy link
Contributor

@alexcrichton Yeah, I figure if it's assumed that you already need that import to work with the type in question, the example doesn't need to show it.

@huonw
Copy link
Member

huonw commented Jul 18, 2014

I'm still in favour of adding the imports both here and for DList: as a single line, they're not much noise, but make the example clearer; especially when one has to use the Deque trait as well as the type, because "Deque" isn't mentioned in the example at all.

(Yes, people could find this out by reading rest of the RingBuf documentation, but no, they don't, or they forget.)

@lilyball
Copy link
Contributor

Seems to me Deque actually belongs in the prelude. Every other std::collections trait is in there.

@alexcrichton
Copy link
Member

Removed r+ for now. Let's please not add anything to the prelude in this PR, let's just perhaps add the imports back in, but the shorter form like I mentioned, this will help with copy/pasting examples.

@nham
Copy link
Contributor Author

nham commented Jul 18, 2014

Done.

@nham
Copy link
Contributor Author

nham commented Jul 25, 2014

I fixed an issue with one of the examples that was preventing tests from passing. Also I've changed every push_back call to push

/// buf.push(3i);
/// buf.push(4);
/// buf.push(5);
/// assert!(buf.get(1) == &4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Deque is no longer used in these examples, so it should be removed. These assert!()s should also be changed to assert_eq!().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I didn't realize that the push() methods are from a different trait. I've fixed this now.

@alexcrichton
Copy link
Member

Could you squash the commits together as well?

@nham
Copy link
Contributor Author

nham commented Jul 26, 2014

Done

bors added a commit that referenced this pull request Jul 26, 2014
This adds examples for get(), get_mut(), swap(), iter() and mut_iter()
@bors bors closed this Jul 26, 2014
@bors bors merged commit ebe8097 into rust-lang:master Jul 26, 2014
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 13, 2023
fix: Fix metrics workflow to use deploy key

I think this should be correct
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.

5 participants