byte-array-struct 0.1.0

Macro to create a byte-array backed struct
Documentation
= Byte Array Struct type for Rust

image:https://travis-ci.org/emeraldpay/byte-array-struct.svg?branch=master["Travis CI", link="https://travis-ci.org/emeraldpay/byte-array-struct"]
image:https://img.shields.io/crates/v/byte-array-struct.svg?style=flat-square["Crates", link="https://crates.io/crates/byte-array-struct"]
image:https://img.shields.io/badge/License-Apache%202.0-blue.svg["License"]


Provides a macro to allows creation of a simple byte-array backed structs. Such struct has a predefined size and
allocated on stack.

== Usage

=== Dependency

----
[dependencies]
byte-array-struct = "0.1"
----

=== Example

[source, rust]
----
// create struct named Address backed by [u8; 24]`
byte_array_struct!(
    pub struct Address(24);
);

impl Address {
    // any additional functionality for Address type
}

// passed as a value on stack
fn send(to: Address) {
   // ...
}

fn main() {
  //accepts hex, which can also be prefixed with 0x
  let foo = Address::from_str("0123456789abcdef0123456789abcdef0123456789abcdef").unwrap();

  send(foo);
}
----

=== Features

Macro provides implementation for following traits:

- `.deref()`
- `.from_str(s)`, which accepts a hex string with the length of target array; may be optionally prefixed with `0x`
- `.to_string()`
- `.from([u8; ...])` and `.from(&[u8; ...])`, where `...` is the defined size
- `.try_from(Vec<u8>)` and `.try_from(&[u8])`
- `.into(Vec<u8>)` and `.into([u8; ...])`
- `.serialize` and `.deserialize` for Serde, with `serialize` feature enabled (default)

== License

Copyright 2020 ETCDEV GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.