From 57af2e9472dbd3263ff5e8f33a61e1c51641cc79 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 9 Jun 2014 14:25:55 -0700 Subject: [PATCH 1/2] RFC for index traits --- active/0000-index-traits.md | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 active/0000-index-traits.md diff --git a/active/0000-index-traits.md b/active/0000-index-traits.md new file mode 100644 index 0000000000000..039560b99ae1e --- /dev/null +++ b/active/0000-index-traits.md @@ -0,0 +1,46 @@ +- Start Date: 2014-06-09 +- RFC PR #: (leave this empty) +- Rust Issue #: #6515 + +# Summary + +`Index` should be split into `Index`, `IndexMut`, and `IndexAssign` + +# Motivation + +Currently, the `Index` trait is not suitable for most array indexing tasks. The slice functionality cannot be replicated using it, and as a result the new `Vec` has to use `.get()` and `.get_mut()` methods. + +Additionally, this simply follows the `Deref`/`DerefMut` split that has been implemented for a while. + +# Detailed design + +We split `Index` into three traits (borrowed from @nikomatsakis): + + // self[element] -- if used as rvalue, implicitly a deref of the result + trait Index { + fn index<'a>(&'a self, element: &E) -> &'a R; + } + + // &mut self[element] -- when used as a mutable lvalue + trait IndexMut { + fn index_mut<'a>(&'a mut self, element: &E) -> &'a mut R; + } + + // self[element] = value + trait IndexSet { + fn index_set(&mut self, element: E, value: V); + } + +# Drawbacks + +* The number of lang. items increases. + +* This design doesn't support moving out of a vector-like object. + +# Alternatives + +The impact of not doing this is that the `[]` notation will not be available to `Vec`. + +# Unresolved questions + +None that I'm aware of. From 4ca734f49f36aeaf0cb35604779df554faeb9d6b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 24 Jun 2014 17:29:46 -0700 Subject: [PATCH 2/2] Accepted RFC 34: Index trait reform --- ...{0000-index-traits.md => 0034-index-traits.md} | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) rename active/{0000-index-traits.md => 0034-index-traits.md} (76%) diff --git a/active/0000-index-traits.md b/active/0034-index-traits.md similarity index 76% rename from active/0000-index-traits.md rename to active/0034-index-traits.md index 039560b99ae1e..9e2acf553cb95 100644 --- a/active/0000-index-traits.md +++ b/active/0034-index-traits.md @@ -1,10 +1,10 @@ - Start Date: 2014-06-09 -- RFC PR #: (leave this empty) +- RFC PR #: #111 - Rust Issue #: #6515 # Summary -`Index` should be split into `Index`, `IndexMut`, and `IndexAssign` +`Index` should be split into `Index` and `IndexMut`. # Motivation @@ -14,7 +14,7 @@ Additionally, this simply follows the `Deref`/`DerefMut` split that has been imp # Detailed design -We split `Index` into three traits (borrowed from @nikomatsakis): +We split `Index` into two traits (borrowed from @nikomatsakis): // self[element] -- if used as rvalue, implicitly a deref of the result trait Index { @@ -26,16 +26,13 @@ We split `Index` into three traits (borrowed from @nikomatsakis): fn index_mut<'a>(&'a mut self, element: &E) -> &'a mut R; } - // self[element] = value - trait IndexSet { - fn index_set(&mut self, element: E, value: V); - } - # Drawbacks * The number of lang. items increases. -* This design doesn't support moving out of a vector-like object. +* This design doesn't support moving out of a vector-like object. This can be added backwards compatibly. + +* This design doesn't support hash tables because there is no assignment operator. This can be added backwards compatibly. # Alternatives