From 8d307394092b6aa39fcd0304ae344ac38dcf26e0 Mon Sep 17 00:00:00 2001 From: bluss Date: Mon, 29 Feb 2016 23:52:58 +0100 Subject: [PATCH] Add .as_slice(), .as_mut_slice(), .as_str() Vec and String now have these, so we do too to follow convention. --- src/array_string.rs | 5 +++++ src/lib.rs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/array_string.rs b/src/array_string.rs index a6410c2..2c5f422 100644 --- a/src/array_string.rs +++ b/src/array_string.rs @@ -152,6 +152,11 @@ impl> ArrayString { debug_assert!(length <= self.capacity()); self.len = Index::from(length); } + + /// Return a string slice of the whole `ArrayString`. + pub fn as_str(&self) -> &str { + self + } } impl> Deref for ArrayString { diff --git a/src/lib.rs b/src/lib.rs index 11c710a..3c9305f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -395,6 +395,16 @@ impl ArrayVec { self.clear(); mem::forget(self); } + + /// Return a slice containing all elements of the vector. + pub fn as_slice(&self) -> &[A::Item] { + self + } + + /// Return a mutable slice containing all elements of the vector. + pub fn as_mut_slice(&mut self) -> &mut [A::Item] { + self + } } impl Deref for ArrayVec {