Skip to content

Commit

Permalink
Add CI DOC for linked list
Browse files Browse the repository at this point in the history
--------
1 linked list push to crates-io
2 add into_inner func for def_node

Signed-off-by: guoweikang <[email protected]>
  • Loading branch information
guoweikang committed Oct 22, 2024
1 parent c2c3542 commit d66aa7e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[package]
name = "linked_list"
version = "0.2.0"
version = "0.1.0"
edition = "2021"
authors = ["Wedson Almeida Filho <[email protected]>", "WeiKang Guo <[email protected]>"]
description = "Linked lists that supports arbitrary removal in constant time"
license = "GPL-2.0-or-later"
homepage = "https://github.com/arceos-org/arceos"
repository = "https://github.com/arceos-org/linked_list"
documentation = "https://arceos-org.github.io/linked_list"
documentation = "https://docs.rs/linked_list"
keywords = ["list"]
categories = ["no-std", "rust-patterns"]

[dependencies]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# LinkedList

[![Crates.io](https://img.shields.io/crates/v/linked_list)](https://crates.io/crates/linked_list)
[![Doc.rs](https://docs.rs/linked_list/badge.svg)](https://docs.rs/linked_list)
[![CI](https://github.com/arceos-org/linked_list/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/arceos-org/linked_list/actions/workflows/ci.yml)

Linked lists that supports arbitrary removal in constant time.

It is based on the linked list implementation in [Rust-for-Linux][1].
Expand Down Expand Up @@ -46,7 +50,7 @@
list.push_back(node1);
list.push_back(node2);

//Support Iter
// Support Iter
for (i,e) in list.iter().enumerate() {
assert!(*e.inner() == i);
}
Expand Down
49 changes: 33 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use raw_list::{GetLinks, Links};
#[macro_export(local_inner_macros)]
#[doc(hidden)]
macro_rules! __def_node_internal {
($(#[$meta:meta])* ($($vis:tt)*) struct $name:ident{$type:ty};) => {
($(#[$meta:meta])* ($($vis:tt)*) struct $name:ident($type:ty);) => {
$(#[$meta])*
$($vis)* struct $name {
inner: $type,
Expand All @@ -35,10 +35,16 @@ macro_rules! __def_node_internal {
}

#[inline]
#[doc = "Get inner"]
#[doc = "Return the referece of wrapped inner"]
$($vis)* const fn inner(&self) -> &$type {
&self.inner
}

#[inline]
#[doc = "Consumes the `node`, returning the wrapped inner"]
$($vis)* fn into_inner(self) -> $type {
self.inner
}
}

impl core::ops::Deref for $name {
Expand All @@ -51,7 +57,7 @@ macro_rules! __def_node_internal {
}
};

($(#[$meta:meta])* ($($vis:tt)*) struct $name:ident<$gen:ident>{$type:ty};) => {
($(#[$meta:meta])* ($($vis:tt)*) struct $name:ident<$gen:ident>($type:ty);) => {
$(#[$meta])*
$($vis)* struct $name<$gen> {
inner: $type,
Expand All @@ -77,10 +83,16 @@ macro_rules! __def_node_internal {
}

#[inline]
#[doc = "Get inner"]
#[doc = "Return the referece of wrapped inner"]
$($vis)* const fn inner(&self) -> &$type {
&self.inner
}

#[inline]
#[doc = "Consumes the `node`, returning the wrapped inner"]
$($vis)* fn into_inner(self) -> $type {
self.inner
}
}

impl<$gen> core::ops::Deref for $name<$gen> {
Expand Down Expand Up @@ -112,14 +124,14 @@ macro_rules! __def_node_internal {
/// ```rust
/// use linked_list::{def_node, List};
///
/// def_node!(
/// def_node!{
/// /// An example Node with usize
/// struct ExampleNode{usize};
/// struct ExampleNode(usize);
/// /// An example Node with generic Inner type and pub(crate)
/// pub(crate) struct NativeGenericNode{usize};
/// pub(crate) struct NativeGenericNode(usize);
/// /// An example Node with generic Inner type and pub vis
/// pub struct GenericNode<T>{T};
/// );
/// pub struct GenericNode<T>(T);
/// }
///
/// let node1 = Box::new(ExampleNode::new(0));
/// let node2 = Box::new(ExampleNode::new(1));
Expand All @@ -131,9 +143,17 @@ macro_rules! __def_node_internal {
/// for (i,e) in list.iter().enumerate() {
/// assert!(*e.inner() == i);
/// }
///
/// let node1 = list.pop_front().unwrap();
/// let node2 = list.pop_front().unwrap();
///
/// assert!(node1.into_inner() == 0);
/// assert!(node2.into_inner() == 1);
/// assert!(list.pop_front().is_none());
///
/// let node1 = Box::new(GenericNode::new(0));
/// let node2 = Box::new(GenericNode::new(1));
///
/// let mut list = List::<Box<GenericNode<usize>>>::new();
///
/// list.push_back(node1);
Expand All @@ -146,16 +166,13 @@ macro_rules! __def_node_internal {
///
#[macro_export(local_inner_macros)]
macro_rules! def_node {
($(#[$meta:meta])* $sv:vis struct $name:ident{$type:ty}; $($t:tt)*) => {
__def_node_internal!($(#[$meta])* ($sv) struct $name{$type};);
($(#[$meta:meta])* $vis:vis struct $name:ident($type:ty); $($t:tt)*) => {
__def_node_internal!($(#[$meta])* ($vis) struct $name($type););
def_node!($($t)*);

};

($(#[$meta:meta])* $sv:vis struct $name:ident<$gen:ident>{$type:ty}; $($t:tt)*) => {
__def_node_internal!($(#[$meta])* ($sv) struct $name<$gen>{$type};);
($(#[$meta:meta])* $vis:vis struct $name:ident<$gen:ident>($type:ty); $($t:tt)*) => {
__def_node_internal!($(#[$meta])* ($vis) struct $name<$gen>($type););
def_node!($($t)*);

};
() => ()
}

0 comments on commit d66aa7e

Please sign in to comment.