diff --git a/compiler/test_gen/src/gen_list.rs b/compiler/test_gen/src/gen_list.rs index 9a964c3213..c81622475d 100644 --- a/compiler/test_gen/src/gen_list.rs +++ b/compiler/test_gen/src/gen_list.rs @@ -1955,7 +1955,7 @@ fn lists_with_incompatible_type_param_in_if() { "" "# ), - RocStr::empty(), + RocStr::default(), RocStr ); } diff --git a/roc_std/src/lib.rs b/roc_std/src/lib.rs index bc7af662a2..82a461ebdd 100644 --- a/roc_std/src/lib.rs +++ b/roc_std/src/lib.rs @@ -31,7 +31,7 @@ pub enum RocOrder { //#[macro_export] //macro_rules! roclist { // () => ( -// $crate::RocList::empty() +// $crate::RocList::default() // ); // ($($x:expr),+ $(,)?) => ( // $crate::RocList::from_slice(&[$($x),+]) @@ -60,13 +60,6 @@ impl RocList { self.length == 0 } - pub fn empty() -> Self { - Self { - length: 0, - elements: core::ptr::null_mut(), - } - } - pub fn get(&self, index: usize) -> Option<&T> { if index < self.len() { Some(unsafe { @@ -287,6 +280,15 @@ impl RocList { } } +impl Default for RocList { + fn default() -> Self { + Self { + length: 0, + elements: core::ptr::null_mut(), + } + } +} + impl fmt::Debug for RocList { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // RocList { storage: Refcounted(3), elements: [ 1,2,3,4] } @@ -367,13 +369,6 @@ impl RocStr { (self.length as isize) < 0 } - pub fn empty() -> Self { - RocStr { - length: 0, - elements: core::ptr::null_mut(), - } - } - pub fn get(&self, index: usize) -> Option<&u8> { if index < self.len() { Some(unsafe { @@ -460,7 +455,7 @@ impl RocStr { capacity ); if capacity < core::mem::size_of::() { - let mut rocstr = Self::empty(); + let mut rocstr = Self::default(); let target_ptr = rocstr.get_small_str_ptr_mut(); let source_ptr = slice.as_ptr() as *const u8; for index in 0..slice.len() { @@ -548,6 +543,15 @@ impl RocStr { } } +impl Default for RocStr { + fn default() -> Self { + Self { + length: 0, + elements: core::ptr::null_mut(), + } + } +} + impl From<&str> for RocStr { fn from(str: &str) -> Self { Self::from_slice(str.as_bytes())