Skip to content

Some small changes for consistency #8452

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

Closed
wants to merge 1 commit into from
Closed

Conversation

Kimundi
Copy link
Member

@Kimundi Kimundi commented Aug 11, 2013

  • Methodyfied the string ascii extionsion functions - They got added recently, I wrapped them in a trait.
  • Added into_owned() method for vectors - similar to Str's into_owned() function, allows to convert to a owned vector without making a copy if the source is a owned vector.
  • Added or_some method to option - similar to unwrap_or_default, but keeps the values wrapped in an Option. Useful for Option chains, eg Iterator impls.
  • Added DoubleEndedIterator impl to Option - Just for compatibility with generic Iterator functions.
  • Renamed nil.rs to unit.rs - the type got renamed ages ago, it's time the source file is as well.

@bluss
Copy link
Member

bluss commented Aug 11, 2013

.or_some(x) is the same as .or(Some(x)); since the methods are not next to each other in the file, I think you didn't know the latter method.

@@ -707,16 +707,19 @@ pub mod traits {}
/// Any vector that can be represented as a slice.
pub trait Vector<T> {
/// Work with `self` as a slice.
fn as_slice<'a>(&'a self) -> &'a [T];
pub fn as_slice<'a>(&'a self) -> &'a [T];
Copy link
Member

Choose a reason for hiding this comment

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

this pub is redundant and soon to be an error(?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, yeah that is a leftover that I accidentally commited. Is the new rule that no visibility modifiers are allowed inside trait declarations?

@Kimundi
Copy link
Member Author

Kimundi commented Aug 11, 2013

@blake2-ppc: or_some(x) being the same as or(Some(x)) was kinda the idea... I don't really have a better justification for adding it other than 'people on irc liked the idea of having a function with that semantic a few days ago'. I was discussing unwrap_or_default, and noticed that you could just factor out the unwrap part: or_default().unwrap(). And then I renamed -default to some because that is what it is.

It's like take_unwrap: A convenience method so that you don't need to write as much characters for doing the same thing.

@Kimundi
Copy link
Member Author

Kimundi commented Aug 11, 2013

Link to IRC snipped that motivated or_some: https://botbot.me/mozilla/rust/msg/5115035/

@Kimundi
Copy link
Member Author

Kimundi commented Aug 13, 2013

After some discussion on IRC I removed the or_some() method for now because it was not clear if it is needed.

Added into_owned() method for vectors
Added DoubleEnded Iterator impl to Option
Renamed nil.rs to unit.rs
bors added a commit that referenced this pull request Aug 14, 2013
- Methodyfied the string ascii extionsion functions - They got added recently, I wrapped them in a trait.
- Added `into_owned()` method for vectors - similar to `Str`'s `into_owned()` function, allows to convert to a owned vector without making a copy if the source is a owned vector.
- Added `or_some` method to option - similar to `unwrap_or_default`, but keeps the values wrapped in an `Option`. Useful for `Option` chains, eg Iterator impls.
- Added `DoubleEndedIterator` impl to `Option` - Just for compatibility with generic Iterator functions.
- Renamed nil.rs to unit.rs - the type got renamed ages ago, it's time the source file is as well.
@bors bors closed this Aug 14, 2013
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