-
Notifications
You must be signed in to change notification settings - Fork 174
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
Writeable LengthHint should be called LengthBound #4709
Comments
Alternatively, we could just return an integer with the following invariant, which should cover all of our cases and maybe do it better:
This would permit a Writeable to estimate an upper bound while still permitting edge cases to exceed it. |
I think it should stay a hint, and we add that guidance yes. |
I think it should stay a hint, similar to iterator. Giving an incorrect hint will not produce incorrect or undefined behaviour, it's just a bit less efficient. |
I think we should either:
|
Which code? |
We have code that assumes it can skip calling |
yes, I am asking to see the code. I think this discussion is not possible without being able to determine if that code really should be doing that and if that helps. |
Also if it's a zero thing we can still say something of the form that it's approximate but zero means zero |
The code is in the writeable crate itself, but it is demonstrative of the type of assumption that other client code could want to be making icu4x/utils/writeable/src/lib.rs Line 265 in 29a3253
fn write_to_string(&self) -> Cow<str> {
let hint = self.writeable_length_hint();
if hint.is_zero() {
return Cow::Borrowed("");
}
let mut output = String::with_capacity(hint.capacity());
let _ = self.write_to(&mut output);
Cow::Owned(output)
} |
Okay, I think we have two paths:
|
I feel like my proposal to change the hint to an integer instead of an enum has gotten a bit lost in the shuffle. |
I think that could work, though I think in that case we still would want to be able to signal the difference between "empty" and "hint zero". |
|
@robertbastian What are your thoughts on "hint" vs "bound"? |
I think we should follow |
I'm not convinced of this use case, but since we don't have consensus, I'll move this issue out of the 2.x milestone and into the Utilities 1.0 milestone. |
We call it a hint, but it is stronger than a hint. The Writeable is required to conform to what it returns, or else it is not a valid Writeable. For example, if it returns a maximum length of 0, then it is valid to return an empty string without ever calling
write_to
.OK?
The text was updated successfully, but these errors were encountered: