How to apply function that returns Result to each element of HashSet in Rust

As a language that aims for safety and performance, Rust provides a powerful data structure called HashSet that provides a fast and efficient way to store and retrieve unique values. HashSet is optimized for scenarios where you need to check for the presence of a value and avoid duplicates, making it a popular choice among… Read More How to apply function that returns Result to each element of HashSet in Rust

Parse over large JSON array of Objects from Facebook

This is the JSON array: { "id": "", "name": "", "posts": { "data": [ { "likes": { "data": [ ], "paging": { "cursors": { "before": "QVFIUnpFd2IwMlhuOWI3dJqelFNNEZAPWDlqeENTNkg1N2RqMm9zQXBreVV6bE9KNXJzX29LeXlMZAzhNT2x3TEhlcGk3OG1Bd3ZABRmpyTXhnNDZAWV2hR", "after": "QVFIUl9Vbm14cld0dm41OTFtKYmgtelBKall2bnBINjBQMXBiNkNCMUM0d21lQXptOXRvbklkU0pHbV9yejNBVG9Jb2hqQTFoem1mdm9zMnJn" }, "next": "" }, "summary": { "total_count": 84, "can_like": true, "has_liked": false } }, "comments": { "data": [ { "created_time": "2022-05-25T18:22:19+0000", "message": "", "id": "" }, {… Read More Parse over large JSON array of Objects from Facebook

How to convert lifetime of boxed reference without allocating a new box?

Context Playground, This works: fn get_owned_box_working<‘a>(b: Box<&’a i32>) -> Box<&’static i32> { Box::new(&42) } but this doesn’t: fn get_owned_box_broken<‘a>(b: Box<&’a i32>) -> Box<&’static i32> { *b = &42; b } error[E0308]: mismatched types –> src/lib.rs:3:5 | 3 | b | ^ lifetime mismatch | = note: expected struct `Box<&’static i32>` found struct `Box<&’a i32>` note:… Read More How to convert lifetime of boxed reference without allocating a new box?

Implementing ToOwned ('a -> 'static) for an enum containing Cow<'a, str> causes unmet lifetime requirement

Context Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=de1286b8bce0dfb840a5fc0b50df25ad I was reading this other SO post, which was saying you can convert a struct containing a Cow to have a ‘static lifetime. Based on that post, I then tried the following: use std::borrow::Cow; enum S<‘a> { A(Cow<‘a, str>), B(i32) } impl ToOwned for S<‘_> { type Owned = S<‘static>; fn… Read More Implementing ToOwned ('a -> 'static) for an enum containing Cow<'a, str> causes unmet lifetime requirement

how to access docker service in localhost

I creates a simple service with docker image. how I want to access it in localhost of my system. docker service create –name my-app –replicas 3 -p 9090:8000 my-app-image docker service ls ID NAME MODE REPLICAS IMAGE PORTS ojvi1m6f8b41 my-app replicated 3/3 my-app-image:latest *:9090->8000/tcp docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 92b7d0ee0732… Read More how to access docker service in localhost

Shared object reference between different Rust containers without copy

I want to have multiple data containers for the same object with the same reference (pointer), and can’t figure out how to achieve that in Rust. Go can simply use reference to the object as below: type container struct { id int status string } m1 := make(map[int]*container) m2 := make(map[int]*container) c := &container{id: 1,… Read More Shared object reference between different Rust containers without copy

overflow instead of saturation on 16bit add AVX2

I want to add 2 unsigned vectors using AVX2 __m256i i1 = _mm256_loadu_si256((__m256i *) si1); __m256i i2 = _mm256_loadu_si256((__m256i *) si2); __m256i result = _mm256_adds_epu16(i2, i1); however I need to have overflow instead of saturation that _mm256_adds_epu16 does to be identical with the non-vectorized code, is there any solution for that? >Solution : Use normal… Read More overflow instead of saturation on 16bit add AVX2