From bdc1b7a8a71b0168a26e1f897246abc6c6ab1091 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 9 Oct 2012 08:36:06 -0700 Subject: [PATCH] libcore: add a str::with_capacity to match the fn in vec --- src/libcore/str.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index d743f0c7f3be1..33016bf9923e8 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1473,6 +1473,11 @@ pub pure fn from_utf16(v: &[u16]) -> ~str { move buf } +pub pure fn with_capacity(capacity: uint) -> ~str { + let mut buf = ~""; + unsafe { reserve(&mut buf, capacity); } + move buf +} /** * As char_len but for a slice of a string