diff --git a/crates/roc_std/src/roc_list.rs b/crates/roc_std/src/roc_list.rs index b7170657fa..a6e91ce187 100644 --- a/crates/roc_std/src/roc_list.rs +++ b/crates/roc_std/src/roc_list.rs @@ -483,6 +483,12 @@ where } } +impl From<[T; SIZE]> for RocList { + fn from(array: [T; SIZE]) -> Self { + Self::from_iter(array) + } +} + impl<'a, T> IntoIterator for &'a RocList { type Item = &'a T; type IntoIter = core::slice::Iter<'a, T>; diff --git a/crates/roc_std/tests/test_roc_std.rs b/crates/roc_std/tests/test_roc_std.rs index 8423d4a537..9c5d9c1824 100644 --- a/crates/roc_std/tests/test_roc_std.rs +++ b/crates/roc_std/tests/test_roc_std.rs @@ -221,6 +221,24 @@ mod test_roc_std { assert_eq!(from_iter, from_slice); } + #[test] + fn list_from_array() { + let elems: [i64; 5] = [1, 2, 3, 4, 5]; + let from_slice = RocList::from_slice(&elems); + let from_array = RocList::from(elems); + assert_eq!(from_array, from_slice); + assert_eq!(from_array.capacity(), from_slice.capacity()); + } + + #[test] + fn list_from_array_zero_size() { + let elems: [(); 5] = [(), (), (), (), ()]; + let from_slice = RocList::from_slice(&elems); + let from_array = RocList::from(elems); + assert_eq!(from_array, from_slice); + assert_eq!(from_array.capacity(), from_slice.capacity()); + } + #[test] fn roc_result_to_rust_result() { let greeting = "Hello, World!";