We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ad21976 commit c0a9979Copy full SHA for c0a9979
src/libcore/str.rs
@@ -94,6 +94,7 @@ export
94
char_at,
95
reserve,
96
reserve_at_least,
97
+ capacity,
98
99
unsafe;
100
@@ -1530,6 +1531,18 @@ fn reserve_at_least(&s: str, n: uint) unsafe {
1530
1531
reserve(s, uint::next_power_of_two(n + 1u) - 1u)
1532
}
1533
1534
+#[doc = "
1535
+Returns the number of single-byte characters the string can hold without
1536
+reallocating
1537
+"]
1538
+fn capacity(&&s: str) -> uint unsafe {
1539
+ as_bytes(s) {|buf|
1540
+ let vcap = vec::capacity(buf);
1541
+ assert vcap > 0u;
1542
+ vcap - 1u
1543
+ }
1544
+}
1545
+
1546
#[doc = "Unsafe operations"]
1547
mod unsafe {
1548
export
0 commit comments