Comments (7)
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 avec<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 😅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.
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.
I'd like to work on this since I'll be using this to implement Qwant [#317]
from websurfx.
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.
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.
Is it okay for the return type to be a
Result<Vec<u8>, EngineError>
instead ofResult<&[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 insteadwhat 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.
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 avec<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 😅
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)
- :zap: Compression for the page responses of the search engine HOT 1
- :children_crossing: Display the user provided settings from the config or the UI in the settings page HOT 1
- 🐛 Results from different search engines get cached as the same key HOT 4
- :recycle: Standardize the `content-type` header by using an enum value over typing it manually HOT 5
- 🐛 Pagination for the upstream search engines not working HOT 1
- 🐛 `Librex` engine only returns one result on the search page HOT 3
- 🐛 Minification of javascript files fails while running the build command HOT 1
- :zap: Several optimizations for improving the performance of the engine HOT 2
- ✨ Categories tabs for different search content in the search page HOT 1
- 📝 Revise the `docs` to remain in sync with the current changes HOT 1
- 👷 Clippy/Format checking/linting GitHub action to analyze code for all the features HOT 1
- 🐛 Undeclared `mini-mocha` crate error when building the app with features other than `memory-cache` HOT 1
- 📝 `Stargazers` roaster link in the `readme` HOT 4
- 🐛 `parsed_cet` not found in scope error when building the app with the `no-cache` feature HOT 1
- 📝 Maintained badge/shield status in the `readme` from `stale` to `yes/maintained` HOT 1
- :sparkles: Support for the ARM architecture (raspberry pi) HOT 2
- :children_crossing: Thin `lto` for the compilation instead of fat `lto` to improve build times HOT 5
- ✨ Support json for the config format HOT 3
- ✨ restructure the config to have different layers for better composability HOT 4
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 websurfx.