From 90fb08c229d444442df745da286d613d1679192f Mon Sep 17 00:00:00 2001 From: Rain Date: Tue, 12 Mar 2019 18:19:16 -0700 Subject: [PATCH] add AsRef impl for Index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is useful for generic code, as the comment says. As a workaround I've had to define a newtype wrapper around `Index` to achieve the same goal, so it would be lovely to have this be upstream! 😄 --- proptest/src/sample.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/proptest/src/sample.rs b/proptest/src/sample.rs index 65b46943..919903c4 100644 --- a/proptest/src/sample.rs +++ b/proptest/src/sample.rs @@ -244,6 +244,14 @@ impl Index { } } +// This impl is handy for generic code over any type that exposes an internal `Index` -- with it, +// a plain `Index` can be passed in as well. +impl AsRef for Index { + fn as_ref(&self) -> &Index { + self + } +} + mapfn! { [] fn UsizeToIndex[](raw: usize) -> Index { Index(raw)