mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
Add RocList from array
This commit is contained in:
parent
b1e41a5995
commit
f70993c2a3
2 changed files with 24 additions and 0 deletions
|
@ -483,6 +483,12 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T, const SIZE: usize> From<[T; SIZE]> for RocList<T> {
|
||||||
|
fn from(array: [T; SIZE]) -> Self {
|
||||||
|
Self::from_iter(array)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, T> IntoIterator for &'a RocList<T> {
|
impl<'a, T> IntoIterator for &'a RocList<T> {
|
||||||
type Item = &'a T;
|
type Item = &'a T;
|
||||||
type IntoIter = core::slice::Iter<'a, T>;
|
type IntoIter = core::slice::Iter<'a, T>;
|
||||||
|
|
|
@ -221,6 +221,24 @@ mod test_roc_std {
|
||||||
assert_eq!(from_iter, from_slice);
|
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]
|
#[test]
|
||||||
fn roc_result_to_rust_result() {
|
fn roc_result_to_rust_result() {
|
||||||
let greeting = "Hello, World!";
|
let greeting = "Hello, World!";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue