alexpovel / b4s

Perform binary search on a single, delimited string slice of sorted but unevenly sized substrings.
https://docs.rs/b4s/
MIT License
5 stars 0 forks source link

Decide on ownership of SortedString #8

Closed alexpovel closed 1 year ago

alexpovel commented 1 year ago

It's easiest for data structures to own their constituents. Makes sense. Structs holding references propagate the resulting, special lifetime requirement all the way up to each user. It's almost like struct colouring, the way async leads to function colouring in languages like Python.

In that sense, it would be nice for SortedString to hold a String, not a &str. Would make working with it much easier. Technically it's unnecessary as all we need is a readonly view into the string though...

alexpovel commented 1 year ago

Noble goal, but with this method and its const nature:

https://github.com/alexpovel/b4s/blob/7bbbbe2b43ccfb2a76bca3d092ac20379da32ca5/src/lib.rs#L461-L463

one cannot have String at compile time, as it's heap allocated. RIP. The impact should be minimal though.