-
Notifications
You must be signed in to change notification settings - Fork 60
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
Provide IndexMut for Vector<T: Clone> (Issue #30) #37
Conversation
Thanks for your contribution! Looking at travis, you need to do a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a few minor details and it is good to go :)
src/vector/mod.rs
Outdated
@@ -444,6 +464,25 @@ impl<T> Vector<T> { | |||
} | |||
} | |||
|
|||
impl<T: Clone> Vector<T> { | |||
/// Gets a mutable reference to an element. If the element is shared, this Vector will be cloned. | |||
/// Returns **None** if and only if the given **index** is out of range. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backtick None
and index
instead of bold
src/vector/mod.rs
Outdated
@@ -444,6 +464,25 @@ impl<T> Vector<T> { | |||
} | |||
} | |||
|
|||
impl<T: Clone> Vector<T> { | |||
/// Gets a mutable reference to an element. If the element is shared, this Vector will be cloned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is best to say "If the element is shared it will be cloned.". It is true for all mutable operations that part of the vector will be cloned.
src/vector/test.rs
Outdated
v2[4] = String::from("cloning"); | ||
v2[5].make_ascii_uppercase(); | ||
|
||
for i in 0..v1.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the loop we can just
assert_eq!(v1, expected1);
assert_eq!(v2, expected2);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looping through because the vectors are not actually the same type. I'll change the implementation for the PartialEq
and PartialOrd
so that this does work.
…Ord|Eq]<U> and make small changes to comments
Merged! Thanks! |
Here's some work towards #30. I don't think its possible to implement for Vector<T: !Clone>.
I'm pretty new to Rust, so any constructive criticism would be appreciated.