-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace closure-based Reader methods like string_ref_map
#335
Comments
In my work on #345 I found that NLL was not the only reason we had created the The raw binary reader wraps a provided
This second step is necessary because the Ion reader doesn't control the input buffer. If it's not big enough to hold the next input value, the reader can't reallocate the buffer to fix that. Instead, it manages its own backup. Once the bytes are in-memory, the reader can apply the user's closure to the If we rewrite the |
An addendum: because these methods (now named As a temporary workaround, these methods have added the However, it also means there's no good way to implement the constrained methods in our The methods we'll implement in the near future will fix this problem because they do not require generics, only lifetimes. // Replace this:
fn map_string<F, U>(&mut self, f: F) -> IonResult<U>
where
Self: Sized,
F: FnOnce(&str) -> U,
{
// ...
}
// With this:
fn read_str(&mut self) -> IonResult<&str> {
// ...
} |
Replaces `map_blob`, `map_clob`, and `map_string` with `read_` equivalents. Fixes issue #335.
Fixed by #509. |
Several methods in the
Cursor
/SystemReader
trait were implemented before Non-Lexical Lifetimes (NLL) were stabilized in Rust 1.31. Back then, borrowing a reference to something could really complicate downstream code, requiring the programmer to add extra scopes to clarify when a reference would stop being used.The methods below allowed the user to specify a closure that take a reference as a parameter; the user could read/copy/analyze the data and return it without scoping issues.
https://github.com/amzn/ion-rust/blob/739d74c57347746fdde3ab5a8844ed824c2b5662/src/cursor.rs#L75-L91
https://github.com/amzn/ion-rust/blob/739d74c57347746fdde3ab5a8844ed824c2b5662/src/cursor.rs#L99-L104
https://github.com/amzn/ion-rust/blob/739d74c57347746fdde3ab5a8844ed824c2b5662/src/cursor.rs#L109-L114
Now that we have NLL, this approach is no longer necessary. It'd be simpler to just give out a reference to the data.
The text was updated successfully, but these errors were encountered: