From 8141e14ace684b6e29ba4ef695a20b0c731b6621 Mon Sep 17 00:00:00 2001 From: Luro02 <24826124+Luro02@users.noreply.github.com> Date: Sat, 12 Oct 2019 17:49:25 +0200 Subject: [PATCH] constify len and is_empty --- src/liballoc/string.rs | 4 ++-- src/liballoc/vec.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 639124e26cc20..ccaf0bae56736 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1380,7 +1380,7 @@ impl String { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.vec.len() } @@ -1399,7 +1399,7 @@ impl String { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() == 0 } diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 6350b189c5faa..82f6653c4ca0f 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1271,7 +1271,7 @@ impl Vec { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { self.len } @@ -1287,7 +1287,7 @@ impl Vec { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + pub const fn is_empty(&self) -> bool { self.len() == 0 }