Git Product home page Git Product logo

Comments (4)

Shnatsel avatar Shnatsel commented on September 26, 2024 1

I'll work on adding limits to animation decoders such as GIF using the existing API, then see if there's any benefit to changing it once we have more internal use of the Limits.reserve() API.

from image.

Shnatsel avatar Shnatsel commented on September 26, 2024

So I've prototyped the .reserved() design and I can't say it's particularly great: https://github.com/Shnatsel/image/tree/raii-limits

There seems to be no way to put #[must_use] on the returned Limits. So it's easy to assume the method mutates the instance of the Limits that you have when it actually doesn't. And I don't want to introduce a confusing API.

It is possible to put #[must_use] on Limits and enforce the use of the return value that way!

from image.

Shnatsel avatar Shnatsel commented on September 26, 2024

On Discord, moulins suggested enforcing stacking of Limits using a lifetime:

struct Limits<'a>(...);

impl<'a> Limit<'a> {
  #[must_use]
  pub fn reserved(&mut self, bytes: usize) -> ImageResult<Limits<'_>>;
}

from image.

fintelia avatar fintelia commented on September 26, 2024

I think it would be easier to think about this in the context of a specific decoder's use of the Limits object. For some decoders, all the actual allocations happen in a dependency and we simply use the value in limits to set the relevant parameter for that crate. In other cases, the allocation might happen in this crate but be on the heap and outlive the specific function that does the allocation.

One other thing from looking at the Limits struct is that I'm not particular sure why its methods are public in the first place? The main place you'd want to call them are from the implementations of decoders. But because decoders are generally either implemented within this crate or imported as dependencies (and thus would cause circular dependencies if their tried to use types from this crate) that doesn't really help.

from image.

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.