mirror of
https://github.com/rust-embedded/heapless.git
synced 2025-10-02 06:50:32 +00:00
Implement Clone for Queue
This commit is contained in:
parent
582668cb50
commit
e272ca9c70
@ -362,6 +362,30 @@ macro_rules! impl_ {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, N, C> Clone for Queue<T, N, $uxx, C>
|
||||
where
|
||||
T: Clone,
|
||||
N: ArrayLength<T>,
|
||||
C: sealed::XCore,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
let mut new = Queue {
|
||||
buffer: unsafe { MaybeUninit::uninitialized() },
|
||||
head: Atomic::new(0),
|
||||
tail: Atomic::new(0),
|
||||
};
|
||||
for s in self.iter() {
|
||||
unsafe {
|
||||
// NOTE(unsafe) new.capacity() == self.capacity() <= self.len()
|
||||
// no overflow possible
|
||||
new.enqueue_unchecked(s.clone());
|
||||
}
|
||||
}
|
||||
new
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user