util docs

This commit is contained in:
debris 2016-02-01 15:22:42 +01:00
parent 6ec672a1a6
commit 2bddc938af
8 changed files with 101 additions and 98 deletions

View File

@ -1,3 +1,5 @@
//! Ethcore crypto.
use hash::*;
use bytes::*;
use uint::*;

View File

@ -1,41 +1,41 @@
/// General IO module.
///
/// Example usage for craeting a network service and adding an IO handler:
///
/// ```rust
/// extern crate ethcore_util;
/// use ethcore_util::*;
///
/// struct MyHandler;
///
/// #[derive(Clone)]
/// struct MyMessage {
/// data: u32
/// }
///
/// impl IoHandler<MyMessage> for MyHandler {
/// fn initialize(&self, io: &IoContext<MyMessage>) {
/// io.register_timer(0, 1000).unwrap();
/// }
///
/// fn timeout(&self, _io: &IoContext<MyMessage>, timer: TimerToken) {
/// println!("Timeout {}", timer);
/// }
///
/// fn message(&self, _io: &IoContext<MyMessage>, message: &MyMessage) {
/// println!("Message {}", message.data);
/// }
/// }
///
/// fn main () {
/// let mut service = IoService::<MyMessage>::start().expect("Error creating network service");
/// service.register_handler(Arc::new(MyHandler)).unwrap();
///
/// // Wait for quit condition
/// // ...
/// // Drop the service
/// }
/// ```
//! General IO module.
//!
//! Example usage for craeting a network service and adding an IO handler:
//!
//! ```rust
//! extern crate ethcore_util;
//! use ethcore_util::*;
//!
//! struct MyHandler;
//!
//! #[derive(Clone)]
//! struct MyMessage {
//! data: u32
//! }
//!
//! impl IoHandler<MyMessage> for MyHandler {
//! fn initialize(&self, io: &IoContext<MyMessage>) {
//! io.register_timer(0, 1000).unwrap();
//! }
//!
//! fn timeout(&self, _io: &IoContext<MyMessage>, timer: TimerToken) {
//! println!("Timeout {}", timer);
//! }
//!
//! fn message(&self, _io: &IoContext<MyMessage>, message: &MyMessage) {
//! println!("Message {}", message.data);
//! }
//! }
//!
//! fn main () {
//! let mut service = IoService::<MyMessage>::start().expect("Error creating network service");
//! service.register_handler(Arc::new(MyHandler)).unwrap();
//!
//! // Wait for quit condition
//! // ...
//! // Drop the service
//! }
//! ```
mod service;
mod worker;

View File

@ -92,32 +92,24 @@ pub mod hash;
pub mod uint;
pub mod bytes;
pub mod rlp;
/// TODO [Gav Wood] Please document me
pub mod misc;
/// TODO [Gav Wood] Please document me
pub mod json_aid;
mod json_aid;
pub mod vector;
pub mod sha3;
pub mod hashdb;
pub mod memorydb;
pub mod overlaydb;
pub mod journaldb;
/// TODO [Gav Wood] Please document me
pub mod math;
mod math;
pub mod chainfilter;
/// TODO [Gav Wood] Please document me
pub mod crypto;
pub mod triehash;
/// TODO [Gav Wood] Please document me
pub mod trie;
pub mod nibbleslice;
mod heapsizeof;
pub mod squeeze;
/// TODO [Gav Wood] Please document me
pub mod semantic_version;
/// TODO [Gav Wood] Please document me
pub mod io;
/// TODO [Gav Wood] Please document me
pub mod network;
pub mod log;

View File

@ -1,4 +1,6 @@
/// log2
//! Common math functions.
/// Returns log2.
pub fn log2(x: usize) -> u32 {
if x <= 1 {
return 0;

View File

@ -1,3 +1,5 @@
//! Diff misc.
use common::*;
#[derive(Debug,Clone,PartialEq,Eq)]

View File

@ -1,52 +1,53 @@
/// Network and general IO module.
/// Example usage for craeting a network service and adding an IO handler:
///
/// ```rust
/// extern crate ethcore_util as util;
/// use util::*;
///
/// struct MyHandler;
///
/// #[derive(Clone)]
/// struct MyMessage {
/// data: u32
/// }
///
/// impl NetworkProtocolHandler<MyMessage> for MyHandler {
/// fn initialize(&self, io: &NetworkContext<MyMessage>) {
/// io.register_timer(0, 1000);
/// }
///
/// fn read(&self, io: &NetworkContext<MyMessage>, peer: &PeerId, packet_id: u8, data: &[u8]) {
/// println!("Received {} ({} bytes) from {}", packet_id, data.len(), peer);
/// }
///
/// fn connected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
/// println!("Connected {}", peer);
/// }
///
/// fn disconnected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
/// println!("Disconnected {}", peer);
/// }
///
/// fn timeout(&self, io: &NetworkContext<MyMessage>, timer: TimerToken) {
/// println!("Timeout {}", timer);
/// }
///
/// fn message(&self, io: &NetworkContext<MyMessage>, message: &MyMessage) {
/// println!("Message {}", message.data);
/// }
/// }
///
/// fn main () {
/// let mut service = NetworkService::<MyMessage>::start(NetworkConfiguration::new()).expect("Error creating network service");
/// service.register_protocol(Arc::new(MyHandler), "myproto", &[1u8]);
///
/// // Wait for quit condition
/// // ...
/// // Drop the service
/// }
/// ```
//! Network and general IO module.
//!
//! Example usage for craeting a network service and adding an IO handler:
//!
//! ```rust
//! extern crate ethcore_util as util;
//! use util::*;
//!
//! struct MyHandler;
//!
//! #[derive(Clone)]
//! struct MyMessage {
//! data: u32
//! }
//!
//! impl NetworkProtocolHandler<MyMessage> for MyHandler {
//! fn initialize(&self, io: &NetworkContext<MyMessage>) {
//! io.register_timer(0, 1000);
//! }
//!
//! fn read(&self, io: &NetworkContext<MyMessage>, peer: &PeerId, packet_id: u8, data: &[u8]) {
//! println!("Received {} ({} bytes) from {}", packet_id, data.len(), peer);
//! }
//!
//! fn connected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
//! println!("Connected {}", peer);
//! }
//!
//! fn disconnected(&self, io: &NetworkContext<MyMessage>, peer: &PeerId) {
//! println!("Disconnected {}", peer);
//! }
//!
//! fn timeout(&self, io: &NetworkContext<MyMessage>, timer: TimerToken) {
//! println!("Timeout {}", timer);
//! }
//!
//! fn message(&self, io: &NetworkContext<MyMessage>, message: &MyMessage) {
//! println!("Message {}", message.data);
//! }
//! }
//!
//! fn main () {
//! let mut service = NetworkService::<MyMessage>::start(NetworkConfiguration::new()).expect("Error creating network service");
//! service.register_protocol(Arc::new(MyHandler), "myproto", &[1u8]);
//!
//! // Wait for quit condition
//! // ...
//! // Drop the service
//! }
//! ```
mod host;
mod connection;
mod handshake;

View File

@ -1,3 +1,5 @@
//! Semantic version formatting and comparing.
/// A version value with strict meaning. Use `to_u32` to convert to a simple integer.
///
/// # Example

View File

@ -1,3 +1,5 @@
//! Trie interface and implementation.
/// TODO [Gav Wood] Please document me
pub mod trietraits;
pub mod standardmap;