3 ms·
I think the point is to have a free method of doing so. Since a &str is a pointer and length, it contains all the information already of where it is inside the
by conradludgate 6y ago
I think the point is to have a free method of doing so. Since a &str is a pointer and length, it contains all the information already of where it is inside the parent &str. This also covers the case of when the same token is repeated in the text.
src = `let abc = "abc"`
token = src[4..7]
The 4 and 7 right there are the values we want. And if a str is a pointer and length, then those values should be retrievable with simple arithmetic, rather than a string search
The only issue is if the str isn't a substring. The signature would need to be either
`fn location(&self, &child) -> Option<(usize, usize)>` or
`unsafe fn location_unchecked(&self, &child) -> (usize, usize) `