Comments (16)
Alternatively, we could just return an integer with the following invariant, which should cover all of our cases and maybe do it better:
Returns the 95th percentile upper bound of bytes required
This would permit a Writeable to estimate an upper bound while still permitting edge cases to exceed it.
from icu4x.
I think it should stay a hint, and we add that guidance yes.
from icu4x.
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.
from icu4x.
I think we should either:
- Make it a
bound
with minimum and maximum (as noted in the OP, we already have code that assumes the bounds are correct) - Make it a
hint
and return an integer instead of a min/max
from icu4x.
Which code?
from icu4x.
We have code that assumes it can skip calling write_to
if write_len
returns an upper bound of 0.
from icu4x.
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.
from icu4x.
Also if it's a zero thing we can still say something of the form that it's approximate but zero means zero
from icu4x.
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)
}
from icu4x.
Okay, I think we have two paths:
- We should declare that zero means zero, everything else is approximate, because that gives the most utility to users whilst leaving things flexible for implementors.
- We treat it as a bound and name it as such.
from icu4x.
I feel like my proposal to change the hint to an integer instead of an enum has gotten a bit lost in the shuffle.
from icu4x.
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".
from icu4x.
Option<usize>
covers that.
from icu4x.
I think it is useful to be able to provide both upper and lower bounds, as this might very well affect the choice of sink that a client uses.
In #370 @sffc proposed an ::Approximate
variant as well, but as of now I don't think we have any writeables that would want to return this.
from icu4x.
@robertbastian What are your thoughts on "hint" vs "bound"?
from icu4x.
I think we should follow Iterator::size_hint
, the same way we use std's fn len
naming instead of fn length
from icu4x.
Related Issues (20)
- `with_locales_no_fallback` does fallback HOT 14
- Remove DynamicDataProvider and expand methods into ExportableProvider HOT 1
- Add Hangul_Syllable_Type enumerated property
- Now might be a good time to figure out off-the-shelf calendar sets in DateTimeFormatter HOT 7
- Transliterator is missing compiled data constructors HOT 4
- Add Temporal CalendarDateDayOfYear to FFI HOT 1
- Incorrect start date for Meiji era HOT 2
- Incorrect week day for Hebrew calendar when ISO year is negative HOT 1
- Integer sizes of day_of_year, day_of_month HOT 1
- Consider proper design for external loader
- Unicode properties `Joining_Group` and `Joining_Type` are not exposed by this library. HOT 1
- Import adjusted UTS 46 data from ICU4C 75 branch HOT 1
- icu_provider_blob contains code that will be rejected by a future version of Rust HOT 1
- Panic when IslamicUmmAlQura month has 31 days HOT 1
- Debug assertion failures with ECMA-262 Temporal.PlainDate minimum and maximum values
- Consider renaming APIs involving daylight time HOT 2
- Field `region_format_variants` is unused in TimeZoneFormatsV1
- Release ICU4X 1.5
- Investigate 353-day Islamic years
- Fix consistency of from_bytes, try_from_bytes, from_str, try_from_str HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from icu4x.