Giter Club home page Giter Club logo

Comments (16)

sffc avatar sffc commented on May 27, 2024

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.

Manishearth avatar Manishearth commented on May 27, 2024

I think it should stay a hint, and we add that guidance yes.

from icu4x.

robertbastian avatar robertbastian commented on May 27, 2024

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.

sffc avatar sffc commented on May 27, 2024

I think we should either:

  1. Make it a bound with minimum and maximum (as noted in the OP, we already have code that assumes the bounds are correct)
  2. Make it a hint and return an integer instead of a min/max

from icu4x.

Manishearth avatar Manishearth commented on May 27, 2024

Which code?

from icu4x.

sffc avatar sffc commented on May 27, 2024

We have code that assumes it can skip calling write_to if write_len returns an upper bound of 0.

from icu4x.

Manishearth avatar Manishearth commented on May 27, 2024

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.

Manishearth avatar Manishearth commented on May 27, 2024

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.

sffc avatar sffc commented on May 27, 2024

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

fn write_to_string(&self) -> Cow<str> {

    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.

Manishearth avatar Manishearth commented on May 27, 2024

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.

sffc avatar sffc commented on May 27, 2024

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.

Manishearth avatar Manishearth commented on May 27, 2024

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.

zbraniecki avatar zbraniecki commented on May 27, 2024

Option<usize> covers that.

from icu4x.

robertbastian avatar robertbastian commented on May 27, 2024

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.

sffc avatar sffc commented on May 27, 2024

@robertbastian What are your thoughts on "hint" vs "bound"?

from icu4x.

robertbastian avatar robertbastian commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.