From 85ecff84687098647e32ada66b605b3827788ed2 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Thu, 22 Sep 2022 15:29:15 -0400 Subject: [PATCH 1/3] add Borrow/BorrowMut for Aligned arrays --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index acc016c..bcac1e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,6 +30,7 @@ #![cfg_attr(not(test), no_std)] use core::{ + borrow::{Borrow, BorrowMut}, cmp::Ordering, fmt::{Debug, Display}, hash::{Hash, Hasher}, @@ -144,6 +145,26 @@ where } } +impl Borrow<[ as AsSlice>::Element]> for Aligned +where + A: sealed::Alignment, + Aligned: AsSlice, +{ + fn borrow(&self) -> &[ as AsSlice>::Element] { + self.as_slice() + } +} + +impl BorrowMut<[ as AsSlice>::Element]> for Aligned +where + A: sealed::Alignment, + Aligned: AsMutSlice, +{ + fn borrow_mut(&mut self) -> &mut [ as AsSlice>::Element] { + self.as_mut_slice() + } +} + impl Clone for Aligned where A: sealed::Alignment, From e96e1cbc11a249c636f78bf27754ae89fdf82338 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Fri, 23 Sep 2022 04:11:50 -0400 Subject: [PATCH 2/3] add a passthrough Borrow/BorrowMut as well, cause duh --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bcac1e5..780f70e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,6 +145,24 @@ where } } +impl Borrow for Aligned +where + A: sealed::Alignment +{ + fn borrow(&self) -> &T { + &self.value + } +} + +impl BorrowMut for Aligned +where + A: sealed::Alignment +{ + fn borrow_mut(&mut self) -> &mut T { + &mut self.value + } +} + impl Borrow<[ as AsSlice>::Element]> for Aligned where A: sealed::Alignment, From 6e540ef9f28fce64f8538c6c473ca8de5b38e9a0 Mon Sep 17 00:00:00 2001 From: Ilya Ostrovskiy Date: Mon, 26 Sep 2022 05:11:43 -0400 Subject: [PATCH 3/3] cargo fmt --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 780f70e..ddd5421 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -147,7 +147,7 @@ where impl Borrow for Aligned where - A: sealed::Alignment + A: sealed::Alignment, { fn borrow(&self) -> &T { &self.value @@ -156,7 +156,7 @@ where impl BorrowMut for Aligned where - A: sealed::Alignment + A: sealed::Alignment, { fn borrow_mut(&mut self) -> &mut T { &mut self.value