| 1 |
# hex |
| 2 |
|
| 3 |
[](https://crates.io/crates/hex) |
| 4 |
[](https://docs.rs/hex) |
| 5 |
[](https://github.com/KokaKiwi/rust-hex/actions) |
| 6 |
|
| 7 |
Encoding and decoding data into/from hexadecimal representation. |
| 8 |
|
| 9 |
## Examples |
| 10 |
|
| 11 |
Encoding a `String` |
| 12 |
|
| 13 |
```rust |
| 14 |
let hex_string = hex::encode("Hello world!"); |
| 15 |
|
| 16 |
println!("{}", hex_string); // Prints "48656c6c6f20776f726c6421" |
| 17 |
``` |
| 18 |
|
| 19 |
Decoding a `String` |
| 20 |
|
| 21 |
```rust |
| 22 |
let decoded_string = hex::decode("48656c6c6f20776f726c6421"); |
| 23 |
|
| 24 |
println!("{}", decoded_string); // Prints "Hello world!" |
| 25 |
``` |
| 26 |
|
| 27 |
You can find the [documentation](https://docs.rs/hex) here. |
| 28 |
|
| 29 |
## Installation |
| 30 |
|
| 31 |
In order to use this crate, you have to add it under `[dependencies]` to your `Cargo.toml` |
| 32 |
|
| 33 |
```toml |
| 34 |
[dependencies] |
| 35 |
hex = "0.4" |
| 36 |
``` |
| 37 |
|
| 38 |
By default this will import `std`, if you are working in a |
| 39 |
[`no_std`](https://rust-embedded.github.io/book/intro/no-std.html) |
| 40 |
environment you can turn this off by adding the following |
| 41 |
|
| 42 |
```toml |
| 43 |
[dependencies] |
| 44 |
hex = { version = "0.4", default-features = false } |
| 45 |
``` |
| 46 |
|
| 47 |
## Features |
| 48 |
|
| 49 |
- `std`: |
| 50 |
Enabled by default. Add support for Rust's libstd types. |
| 51 |
- `serde`: |
| 52 |
Disabled by default. Add support for `serde` de/serializing library. |
| 53 |
See the `serde` module documentation for usage. |
| 54 |
|
| 55 |
## License |
| 56 |
|
| 57 |
Licensed under either of |
| 58 |
|
| 59 |
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 60 |
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 61 |
|
| 62 |
at your option. |
| 63 |
|
| 64 |
### Contribution |
| 65 |
|
| 66 |
Unless you explicitly state otherwise, any contribution intentionally |
| 67 |
submitted for inclusion in the work by you, as defined in the Apache-2.0 |
| 68 |
license, shall be dual licensed as above, without any additional terms or |
| 69 |
conditions. |