mirror of https://git.sr.ht/~stygianentity/bincode
Added documentation on String/&str
This commit is contained in:
parent
174ef41ac9
commit
7cbca87d3e
14
docs/spec.md
14
docs/spec.md
|
|
@ -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'
|
||||
]);
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in New Issue