Giter Site home page Giter Site logo

Comments (7)

neon-mmd avatar neon-mmd commented on June 1, 2024 1

Also, one thing I would like to suggest that is that you don't need to add to_vec() because the .bytes() function already returns a vec<u8> so converting a vec fo a vec does not make sense like it would be an unnecessary conversion and also redundant too.

Can you clarify this for me because I might be missing something here. Because the compiler advises me to use the .to_vec() method. I'm fairly new to the library and the language so please excuse me if I missed something 😅

2024-01-29_19-00

But yeah, I agree, using references should be memory efficient and I would prefer to implement it that way if it's reasonably straightforward. Although, I believe we shouldn't optimize for the sake of optimization (aka "premature optimization"). What do you think 🙂

Yes, I agree, also I think from the compilor error it seems that you will have to go with the to_vec() method to fix this error. So I think that's the only way to fix this. So I would suggest going with the to_vec() method. 🙂

from websurfx.

github-actions avatar github-actions commented on June 1, 2024

The issue has been unlocked and is now ready for dev. If you would like to work on this issue, you can comment to have it assigned to you. You can learn more in our contributing guide https://github.com/neon-mmd/websurfx/blob/rolling/CONTRIBUTING.md

from websurfx.

jfvillablanca avatar jfvillablanca commented on June 1, 2024

I'd like to work on this since I'll be using this to implement Qwant [#317]

from websurfx.

neon-mmd avatar neon-mmd commented on June 1, 2024

I'd like to work on this since I'll be using this to implement Qwant [#317]

Yes sure, we will assign this issue to you. You may start working on it right away 🚀 🙂

from websurfx.

jfvillablanca avatar jfvillablanca commented on June 1, 2024

Is it okay for the return type to be a Result<Vec<u8>, EngineError> instead of Result<&[u8], EngineError>

in other words, instead of:

Ok(client
    .get(url)
    .headers(header_map)
    .send()
    .await
    .change_context(EngineError::RequestError)?
    .bytes() // This returns Bytes causing a compile-time error
    .await
    .change_context(EngineError::RequestError)?)

I rewrite it like this:

Ok(client
    .get(url)
    .headers(header_map)
    .send()
    .await
    .change_context(EngineError::RequestError)?
    .bytes()
    .await
    .change_context(EngineError::RequestError)?
    .to_vec()) // Turn into a Vec instead

what do you think? will this be a suboptimal implementation?

from websurfx.

neon-mmd avatar neon-mmd commented on June 1, 2024

Is it okay for the return type to be a Result<Vec<u8>, EngineError> instead of Result<&[u8], EngineError>

in other words, instead of:

Ok(client
    .get(url)
    .headers(header_map)
    .send()
    .await
    .change_context(EngineError::RequestError)?
    .bytes() // This returns Bytes causing a compile-time error
    .await
    .change_context(EngineError::RequestError)?)

I rewrite it like this:

Ok(client
    .get(url)
    .headers(header_map)
    .send()
    .await
    .change_context(EngineError::RequestError)?
    .bytes()
    .await
    .change_context(EngineError::RequestError)?
    .to_vec()) // Turn into a Vec instead

what do you think? will this be a suboptimal implementation?

Actually, I don't mind both implementations are good, but slices tend to be a little bit more memory efficient, that's why I had put the result with the slices in the sample code. Also, one thing I would like to suggest that is that you don't need to add to_vec() because the .bytes() function already returns a vec<u8> so converting a vec fo a vec does not make sense like it would be an unnecessary conversion and also redundant too. 🙂

from websurfx.

jfvillablanca avatar jfvillablanca commented on June 1, 2024

Also, one thing I would like to suggest that is that you don't need to add to_vec() because the .bytes() function already returns a vec<u8> so converting a vec fo a vec does not make sense like it would be an unnecessary conversion and also redundant too.

Can you clarify this for me because I might be missing something here. Because the compiler advises me to use the .to_vec() method. I'm fairly new to the library and the language so please excuse me if I missed something 😅

2024-01-29_19-00

But yeah, I agree, using references should be memory efficient and I would prefer to implement it that way if it's reasonably straightforward. Although, I believe we shouldn't optimize for the sake of optimization (aka "premature optimization"). What do you think 🙂

from websurfx.

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.