-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* unsafe set_len() implemented * test_drop_after_set_len() implemented * test_set_len() implemented * impl From<LocalVec<T, N>> for [T; N] added * test for converting into array implemented * test for Drop behavior after converting into array * manifest updated
- Loading branch information
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::convert::From; | ||
use crate::LocalVec; | ||
|
||
impl<T, const N: usize> From<LocalVec<T, N>> for [T; N] { | ||
fn from(mut local_vec: LocalVec<T, N>) -> Self { | ||
let arr: [T; N] = unsafe { | ||
local_vec.set_len(0); | ||
std::mem::transmute_copy(&local_vec.buf) | ||
}; | ||
|
||
arr | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_into_array() { | ||
let mut vec = LocalVec::<_, 4>::new(); | ||
vec.push(0); | ||
vec.push(1); | ||
vec.push(2); | ||
vec.push(3); | ||
|
||
let arr: [_; 4] = vec.into(); | ||
assert_eq!(arr[0], 0); | ||
assert_eq!(arr[1], 1); | ||
assert_eq!(arr[2], 2); | ||
assert_eq!(arr[3], 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters