Add unstable-const-fn feature to make new() functions const.

This commit is contained in:
Mara Bos
2020-06-30 16:26:22 +02:00
parent 4043c58de7
commit fe70c23e94
6 changed files with 40 additions and 3 deletions
+12 -1
View File
@@ -58,11 +58,22 @@ impl<A> ArrayString<A>
/// assert_eq!(&string[..], "foo");
/// assert_eq!(string.capacity(), 16);
/// ```
#[cfg(not(feature="unstable-const-fn"))]
pub fn new() -> ArrayString<A> {
unsafe {
ArrayString {
xs: MaybeUninitCopy::uninitialized(),
len: Index::from(0),
len: Index::ZERO,
}
}
}
#[cfg(feature="unstable-const-fn")]
pub const fn new() -> ArrayString<A> {
unsafe {
ArrayString {
xs: MaybeUninitCopy::uninitialized(),
len: Index::ZERO,
}
}
}