From 55b36fd27190f72395d4a6c1144f9ad548aa3f04 Mon Sep 17 00:00:00 2001 From: "Anthony W. Juckel" Date: Fri, 18 May 2018 11:08:35 -0500 Subject: [PATCH] Fix off-by-one error in slice example Using 0-based indexing, &s[6..11] would start _after_ the 6th byte of `s`, and the first element of the slice would contain the 7th byte of `s`. For example, &s[0] references the 1st byte of `s`. --- 2018-edition/src/ch04-03-slices.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2018-edition/src/ch04-03-slices.md b/2018-edition/src/ch04-03-slices.md index 5bf3fec30..8cac17aba 100644 --- a/2018-edition/src/ch04-03-slices.md +++ b/2018-edition/src/ch04-03-slices.md @@ -158,7 +158,7 @@ in the slice and `ending_index` is one more than the last position in the slice. Internally, the slice data structure stores the starting position and the length of the slice, which corresponds to `ending_index` minus `starting_index`. So in the case of `let world = &s[6..11];`, `world` would be -a slice that contains a pointer to the 6th byte of `s` and a length value of 5. +a slice that contains a pointer to the 7th byte of `s` and a length value of 5. Figure 4-6 shows this in a diagram.