From 7cbca87d3e13fa5f9f86ad8fa5b7618ce215a65e Mon Sep 17 00:00:00 2001 From: Victor Koenders Date: Mon, 13 Sep 2021 12:11:24 +0200 Subject: [PATCH] Added documentation on String/&str --- docs/spec.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/spec.md b/docs/spec.md index eab62b0..d506eff 100644 --- a/docs/spec.md +++ b/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`. 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' +]); +```