Skip to content

Commit b7d82be

Browse files
authored
Add some Borrow/BorrowMut trait impls (#16)
* add Borrow/BorrowMut for Aligned arrays * add a passthrough Borrow/BorrowMut as well, cause duh * cargo fmt
1 parent 87e103b commit b7d82be

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/lib.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![cfg_attr(not(test), no_std)]
3131

3232
use core::{
33+
borrow::{Borrow, BorrowMut},
3334
cmp::Ordering,
3435
fmt::{Debug, Display},
3536
hash::{Hash, Hasher},
@@ -170,6 +171,44 @@ where
170171
}
171172
}
172173

174+
impl<A, T> Borrow<T> for Aligned<A, T>
175+
where
176+
A: sealed::Alignment,
177+
{
178+
fn borrow(&self) -> &T {
179+
&self.value
180+
}
181+
}
182+
183+
impl<A, T> BorrowMut<T> for Aligned<A, T>
184+
where
185+
A: sealed::Alignment,
186+
{
187+
fn borrow_mut(&mut self) -> &mut T {
188+
&mut self.value
189+
}
190+
}
191+
192+
impl<A, T> Borrow<[<Aligned<A, T> as AsSlice>::Element]> for Aligned<A, T>
193+
where
194+
A: sealed::Alignment,
195+
Aligned<A, T>: AsSlice,
196+
{
197+
fn borrow(&self) -> &[<Aligned<A, T> as AsSlice>::Element] {
198+
self.as_slice()
199+
}
200+
}
201+
202+
impl<A, T> BorrowMut<[<Aligned<A, T> as AsSlice>::Element]> for Aligned<A, T>
203+
where
204+
A: sealed::Alignment,
205+
Aligned<A, T>: AsMutSlice,
206+
{
207+
fn borrow_mut(&mut self) -> &mut [<Aligned<A, T> as AsSlice>::Element] {
208+
self.as_mut_slice()
209+
}
210+
}
211+
173212
impl<A, T> Clone for Aligned<A, T>
174213
where
175214
A: Alignment,

0 commit comments

Comments
 (0)