Added documentation on String/&str

This commit is contained in:
Victor Koenders 2021-09-13 12:11:24 +02:00
parent 174ef41ac9
commit 7cbca87d3e
1 changed files with 14 additions and 0 deletions

View File

@ -101,3 +101,17 @@ assert_eq!(encoded.as_slice(), &[
```
This also applies to e.g. `HashMap`, where each entry is a [tuple](#Basic%20types) of the key and value.
# String and &str
Both `String` and `&str` are treated as a `Vec<u8>`. See [Collections](#Collections) for more information.
```rs
let str = "Hello"; // Could also be `String::new(...)`
let encoded = bincode::encode_to_vec_with_options(&list, Options::default().with_fixint_encoding()).unwrap();
assert_eq!(encoded.as_slice(), &[
0, 0, 0, 0, 0, 0, 0, 5, // length of the string, 5 bytes
b'H', b'e', b'l', b'l', b'o'
]);
```