Skip to content

Commit

Permalink
Added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Grunert authored and Sascha Grunert committed Dec 20, 2016
1 parent 81c5076 commit 4879bd1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# peel [![Build Status](https://travis-ci.org/saschagrunert/peel.svg)](https://travis-ci.org/saschagrunert/peel) [![Build status](https://ci.appveyor.com/api/projects/status/i67yq6yij2k17iwc?svg=true)](https://ci.appveyor.com/project/saschagrunert/peel) [![Coverage Status](https://coveralls.io/repos/github/saschagrunert/peel/badge.svg?branch=master)](https://coveralls.io/github/saschagrunert/peel?branch=master) [![doc peel](https://img.shields.io/badge/doc-peel-blue.svg)](https://saschagrunert.github.io/peel) [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/saschagrunert/peel/blob/master/LICENSE)
## Dynamic packet parsing within trees 馃尣 馃尦 馃尨
Target of this library is to provide a flexible parsing approach for network packets. This will be done within
[arena](https://en.wikipedia.org/wiki/Region-based_memory_management) based [parser trees](https://en.wikipedia.org/wiki/Parse_tree)
which can be modified during runtime. Other stacks beside the well known TCP/IP protocol family should be parsable too.
# indextree [![Build Status](https://travis-ci.org/saschagrunert/indextree.svg)](https://travis-ci.org/saschagrunert/indextree) [![Build status](https://ci.appveyor.com/api/projects/status/byraapuh9py02us0?svg=true)](https://ci.appveyor.com/project/saschagrunert/indextree) [![Coverage Status](https://coveralls.io/repos/github/saschagrunert/indextree/badge.svg?branch=master)](https://coveralls.io/github/saschagrunert/indextree?branch=master) [![doc indextree](https://img.shields.io/badge/doc-indextree-blue.svg)](https://saschagrunert.github.io/indextree) [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/saschagrunert/indextree/blob/master/LICENSE)
## Arena based tree structure
This arena tree structure is using just a single `Vec` and numerical identifiers (indices in the vector) instead of
reference counted pointers like. This means there is no `RefCell` and mutability is handled in a way much more
idiomatic to Rust through unique (&mut) access to the arena. The tree can be sent or shared across threads like a `Vec`.
This enables general multiprocessing support like parallel tree traversals.

### Example usage
```rust
use peel::prelude::*;
use indextree::Arena;

// Get the default tree based on the TCP/IP stack
let peel = peel_tcp_ip();
// Create a new arena
let arena = &mut Arena::new();

let eth_header = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 8, 0];
// Add some new nodes to the arena
let a = arena.new_node(1);
let b = arena.new_node(2);

// Traverse the parser tree. If a parser matches check for available child parsers.
// Stop parsing if there are no childs left. The `vec![]` memory will be used for
// the resulting stack of `Layer`s.
let result = peel.traverse(&eth_header, vec![]).unwrap();

// There should be one parsed EthernetPacket in:
assert_eq!(result.len(), 1);
// Append a to b
a.append(b, arena);
assert_eq!(b.ancestors(arena).into_iter().count(), 2);
```
23 changes: 22 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
//! Arena based tree data structure
//! # Arena based tree data structure
//!
//! This arena tree structure is using just a single `Vec` and numerical identifiers (indices in the vector) instead of
//! reference counted pointers like. This means there is no `RefCell` and mutability is handled in a way much more
//! idiomatic to Rust through unique (&mut) access to the arena. The tree can be sent or shared across threads like a `Vec`.
//! This enables general multiprocessing support like parallel tree traversals.
//!
//! # Example usage
//! ```
//! use indextree::Arena;
//!
//! // Create a new arena
//! let arena = &mut Arena::new();
//!
//! // Add some new nodes to the arena
//! let a = arena.new_node(1);
//! let b = arena.new_node(2);
//!
//! // Append a to b
//! a.append(b, arena);
//! assert_eq!(b.ancestors(arena).into_iter().count(), 2);
//! ```
use std::{mem, fmt};
use std::ops::{Index, IndexMut};

Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate indextree;
use indextree::Arena;

use indextree::*;
use std::cell::Cell;

#[test]
Expand Down

0 comments on commit 4879bd1

Please sign in to comment.