Skip to content

Commit

Permalink
Version 0.12.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk20 committed Mar 2, 2021
1 parent 04fe34c commit 1e96864
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "generic-array"
version = "0.12.0"
version = "0.12.3"
authors = [ "Bartłomiej Kamiński <fizyk20@gmail.com>", "Aaron Trent <novacrazy@gmail.com>" ]

description = "Generic types implementing functionality of arrays"
Expand Down
19 changes: 14 additions & 5 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
N: ArrayLength<T>,
{
fn clone(&self) -> GenericArray<T, N> {
self.map(|x| x.clone())
self.map(Clone::clone)
}
}

Expand Down Expand Up @@ -77,6 +77,7 @@ impl<T, N> Borrow<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn borrow(&self) -> &[T] {
&self[..]
}
Expand All @@ -86,6 +87,7 @@ impl<T, N> BorrowMut<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn borrow_mut(&mut self) -> &mut [T] {
&mut self[..]
}
Expand All @@ -95,6 +97,7 @@ impl<T, N> AsRef<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn as_ref(&self) -> &[T] {
&self[..]
}
Expand All @@ -104,6 +107,7 @@ impl<T, N> AsMut<[T]> for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn as_mut(&mut self) -> &mut [T] {
&mut self[..]
}
Expand All @@ -125,11 +129,16 @@ macro_rules! impl_from {
($($n: expr => $ty: ty),*) => {
$(
impl<T> From<[T; $n]> for GenericArray<T, $ty> {
#[inline(always)]
fn from(arr: [T; $n]) -> Self {
use core::mem::{forget, transmute_copy};
let x = unsafe { transmute_copy(&arr) };
forget(arr);
x
unsafe { $crate::transmute(arr) }
}
}

impl<T> Into<[T; $n]> for GenericArray<T, $ty> {
#[inline(always)]
fn into(self) -> [T; $n] {
unsafe { $crate::transmute(self) }
}
}
)*
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ where
{
type Target = [T];

#[inline(always)]
fn deref(&self) -> &[T] {
unsafe { slice::from_raw_parts(self as *const Self as *const T, N::to_usize()) }
}
Expand All @@ -160,6 +161,7 @@ impl<T, N> DerefMut for GenericArray<T, N>
where
N: ArrayLength<T>,
{
#[inline(always)]
fn deref_mut(&mut self) -> &mut [T] {
unsafe { slice::from_raw_parts_mut(self as *mut Self as *mut T, N::to_usize()) }
}
Expand Down

0 comments on commit 1e96864

Please sign in to comment.