rust/library/core/tests
Guillaume Gomez 86bf3ce859
Rollup merge of #75644 - c410-f3r:array, r=yaahc
Add 'core::array::from_fn' and 'core::array::try_from_fn'

These auxiliary methods fill uninitialized arrays in a safe way and are particularly useful for elements that don't implement `Default`.

```rust
// Foo doesn't implement Default
struct Foo(usize);

let _array = core::array::from_fn::<_, _, 2>(|idx| Foo(idx));
```

Different from `FromIterator`, it is guaranteed that the array will be fully filled and no error regarding uninitialized state will be throw. In certain scenarios, however, the creation of an **element** can fail and that is why the `try_from_fn` function is also provided.

```rust
#[derive(Debug, PartialEq)]
enum SomeError {
    Foo,
}

let array = core::array::try_from_fn(|i| Ok::<_, SomeError>(i));
assert_eq!(array, Ok([0, 1, 2, 3, 4]));

let another_array = core::array::try_from_fn(|_| Err(SomeError::Foo));
assert_eq!(another_array, Err(SomeError::Foo));
 ```
2021-10-09 17:08:38 +02:00
..
fmt Use a test value that doesn't depend on the handling of even/odd rounding 2021-10-03 20:15:12 -07:00
hash move object safety test to library/core 2021-08-15 13:00:25 -04:00
iter implement advance_(back_)_by on more iterators 2021-09-30 21:23:28 +02:00
num Temporarily rename int_roundings functions to avoid conflicts 2021-09-22 13:56:01 -07:00
ops
alloc.rs
any.rs Add test for issue 84666. 2021-06-03 16:13:45 +02:00
array.rs Also cfg flag auxiliar function 2021-10-08 06:40:24 -03:00
ascii.rs
atomic.rs
bool.rs
cell.rs Add a few tests for UnsafeCell 2021-08-31 16:32:01 -07:00
char.rs Further simplification of to_digit 2021-06-10 20:16:35 +01:00
clone.rs
cmp.rs
const_ptr.rs Revert "Revert tests added by PR 81167." 2021-06-27 12:05:17 +02:00
intrinsics.rs
lazy.rs
lib.rs Rollup merge of #75644 - c410-f3r:array, r=yaahc 2021-10-09 17:08:38 +02:00
macros.rs Allow leading pipe in matches!() patterns. 2021-07-15 22:05:45 +03:00
manually_drop.rs Test ManuallyDrop::clone_from. 2021-07-05 11:55:45 +00:00
mem.rs Remove the deprecated core::raw and std::raw module. 2021-07-03 14:03:27 +08:00
nonzero.rs
ops.rs
option.rs const fn for option copied, take & replace + tests 2021-08-29 13:19:17 +02:00
pattern.rs
pin.rs
ptr.rs
result.rs Update to new bootstrap compiler 2021-06-28 11:30:49 -04:00
slice.rs Move to the top of file 2021-08-31 08:28:51 -07:00
str_lossy.rs
str.rs
task.rs
time.rs Make Duration's Debug format pad to width 2021-09-16 03:09:31 +02:00
tuple.rs
unicode.rs