mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: utils: linked_list: do not require clone trait
This commit is contained in:
parent
1ce03e09cc
commit
d2155ed7cf
@ -35,7 +35,6 @@ impl RawCap {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CapEntry {
|
||||
pub cap: Cell<RawCap>,
|
||||
pub link: Link<Self>,
|
||||
@ -59,6 +58,14 @@ impl CapEntry {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for CapEntry {
|
||||
fn clone(&self) -> Self {
|
||||
let mut cte = Self::new(self.cap.get());
|
||||
cte.link = self.link.clone();
|
||||
cte
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RawCap> for CapEntry {
|
||||
fn from(value: RawCap) -> Self {
|
||||
Self::new(value)
|
||||
|
@ -10,7 +10,7 @@ macro_rules! LinkHelperImpl {
|
||||
};
|
||||
}
|
||||
|
||||
pub trait LinkHelper: Clone {
|
||||
pub trait LinkHelper: Sized {
|
||||
const LINK_OFFSET: usize;
|
||||
|
||||
/// # Safety
|
||||
@ -20,7 +20,6 @@ pub trait LinkHelper: Clone {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Link<T: LinkHelper> {
|
||||
pub prev: Cell<Option<NonNull<T>>>,
|
||||
pub next: Cell<Option<NonNull<T>>>,
|
||||
@ -35,6 +34,15 @@ impl<T: LinkHelper> Default for Link<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: LinkHelper> Clone for Link<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
prev: Cell::new(self.prev.get()),
|
||||
next: Cell::new(self.next.get()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: LinkHelper> Link<T> {
|
||||
/// # Safety
|
||||
/// LINK_OFFSET must be a valid field offset of T
|
||||
@ -113,7 +121,6 @@ impl<T: LinkHelper> Link<T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Node {
|
||||
link: Link<Node>,
|
||||
value: i32,
|
||||
|
Loading…
Reference in New Issue
Block a user