- New York City
- https://pub.gajendra.net/
- Joined on
2025-10-08
I'm mildly bummed out that this went away, because it's decently concise, which is nice.
I wonder about extracting this into a small function that wraps an Option or something? Probably not worth it.
I don't think this is what you want, necessarily. You want to find a zero byte, sure, but looking beyond the first len bytes is not useful and may not even be correct, if the source string is not e.g. 0 terminated. I would argue that's a bug, but I could be wrong.
So this will allocate a Vec<u8> to hold the trimmed bytes, and then invoke alloc_string to do another allocation. I don't know if there's a good way around that; perhaps use strndup? Something like,
It feels like you almost don't need this at all; you could do everything you need to do with the Bag abstraction by just making it a newtype over a BTreeMap, and then dereferencing the newtype pointer at the FFI boundary. Something like,
I'm merging this into another branch and will open a PR for that to the main repo, under refactor/wutil-rs.
When you went in and updated calls to malloc/free, did you also look at…