Ver Fonte

some doc

deltanedas há 3 anos atrás
pai
commit
ed52e62c84
3 ficheiros alterados com 24 adições e 0 exclusões
  1. 2 0
      README.md
  2. 4 0
      src/io.rs
  3. 18 0
      src/lib.rs

+ 2 - 0
README.md

@@ -26,6 +26,8 @@ let mut bytes = vec![];
 thingy.write(&mut bytes);
 ```
 
+Under the hood its a generic wrapper over little-endian [byteorder](lib.rs/byteorder) with a derive macro for structs and enums to use.
+
 Named after the cookie :)
 
 # License

+ 4 - 0
src/io.rs

@@ -5,8 +5,12 @@ pub use byteorder::{ReadBytesExt, WriteBytesExt};
 pub type Reader<'a> = &'a [u8];
 pub type Writer = Vec<u8>;
 
+/// A type that can be serialized to and from bytes.
+/// Should only be implemented on types that own their data, i.e. `String` and not `&str`.
 pub trait Io : Sized {
+	/// Read data from the reader.
 	fn read(r: &mut Reader) -> Result<Self>;
 
+	/// Write this data to the reader.
 	fn write(&self, w: &mut Writer) -> Result<()>;
 }

+ 18 - 0
src/lib.rs

@@ -1,3 +1,21 @@
+//! # Io trait
+//! The [Io] trait allows types to be written and read generically to byte vecs.
+//! See its documentation for usage and manual implementation.
+//!
+//! # Derive macro
+//! The derive macro `#[derive(Io)]` can be used to trivially implement `Io` for your types.
+//! All serialized fields must implement the `Io` trait for it to work.
+//! Fields can have the `#[io(ignore)]` attribute added which will:
+//! 1. Ignore the field when writing the full struct/enum.
+//! 2. Use `Default` for reading as there is nothing to read from.
+//!
+//! # Std types
+//! Currently a few types from std are supported:
+//! - All numbers
+//! - `String`
+//! - `Box` `HashMap` `Option` and `Vec` of types that implement `Io`
+//! - `Duration` and `SystemTime`.
+
 use std::io::{Error, ErrorKind};
 
 mod io;