barskern

u/barskern


r/rust•

EDIT: Solved by u/fhsgoncalves solution.

This is not an issue when the warp Filter is Copy (playground), but when I try to add some non-copy state to the Filter I am unable to get it working. I've tried to manually clone the service at multiple points within the closure of the make_service_fn. When I had a similar issue before it worked to add a clone before the async move block (see example below), however that does not work in this case.

Could somebody help me get this to pass the borrowchecker, or is my thoughtprocess fundamentally flawed here?

[Simplified

113

r/rust•

I've recently started a personal project to create a Arena allocator using generational indicies to practice writing Rust. I was curious if it's possible to create index types which are linked to the arena at compile time, such that an index can only be used to index into the arena it came from. I figured out how to do this when the arena contains different types, however when the arenas contains the same type, the indexes are interchangeable (see example). I could "force" the user to make a unique empty type for each arena which has to be given as a generic parameter when creating the arena, but I would prefer to avoid this. Is there another way to accomplish this?

Here is my current code

526

r/KeybaseProofs•

Keybase proof

I am:

Proof:

hKRib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEgPiPj8wSp9IfT5wYtXqbHmWyVzx+w+CcTBGwIG7wJ2TIKp3BheWxvYWTESpcCEcQg/MgCm7wf0MVCDCqcb63fuTFr7Ehn4cfFAf2aUJj9/kTEIMvZ9x6jmBsTQiJKV3YnCxLQeORh1E9G2h+R9GmX3bCFAgHCo3NpZ8RA7s5Tfz21cpQRAmHMWwm1mNhlgN3PGACOx8nipC6I8x+BMIimBBANV2d/X9mUC2TZ2Y0KEUJDgHZpo5/7zK1TBKhzaWdfdHlwZSCkaGFzaIKkdHlwZQildmFsdWXEIFsAzqM4KleYDYDVmzx5DUhs1hfJIohZl6HV+N9E4zvfo3RhZ80CAqd2ZXJzaW9uAQ==
20

r/rust•

I have a situation where I want to create an iterator over &str. When I want to chain some strs which are stored in an array, the item type of the iterator is &&str, which is incompatible with &str. I found a way of solving it, but I was wondering if there is something I'm missing which might make it more elegant. Any suggestions? (see example below)

Further I was wondering if one could generally turn any nested reference to a reference. To rephrase it a bit; can a &&T always be safely turned into a &T?

    let xs = &["b", "c"];
    
    // I wish this would compile, but it gives a error regarding the 
    // item-types not matching: `&am
16

r/rust•

I was working on a task which required to modify two elements of an array at once. At first I though about using split_at_mut with some clever indexing, however I was not pleased with the mental complexity. Hence I wanted to implement a function which ensured that the two given indexes were different and did some unsafe code to take two mutable references. I my head this seems safe because taking two distinct indexes from a slice, should always point to non-overlapping data (this is also true for ZSTs, right?). Hence I created the following trait and implementation:

    /// Extension trait to allow a container
2020


You've reached the end of this feed.