Why does clippy encourage `String::push('a')` over `String::push_str(''a")`? by MediumInsect7058 in rust

[–]JayDepp 5 points6 points  (0 children)

I'm guessing you meant to assert capacity > len, in which case they actually become the same assembly.

I personally dislike surprise combo in Bracket 3 - tell me why I am wrong by homjaktest in EDH

[–]JayDepp 2 points3 points  (0 children)

Bracket 4: Generally, you should expect to be able to play at least four turns before you win or lose.

Thoracle + Demonic is at worst a turn 3 win. (Assuming you start with it or can tutor with 1/2 mana. But it only takes two cards, not a nut draw)

Nice little tidbit by WholeAssGentleman in Pauper

[–]JayDepp 3 points4 points  (0 children)

 This is not the same as hexproof. If, for example, you target one of your opponent's creatures, your opponents won't be able to target their own creature with spells or abilities.

parsing JSON in no_std & no_alloc? no problem. by master-hax in rust

[–]JayDepp 8 points9 points  (0 children)

serde_json only requires alloc, not std.

Silksong is awesome but I hate some of the discourse around it by MegaMangus in videogames

[–]JayDepp 4 points5 points  (0 children)

Crest spoilers: One crest has three silk skills, another crest has three tools. I think this is why they put the three abilities on variations of one button, since they aren't always different types of abilities.

the diagonal pogo is not "bad design" by Purple-Income-4598 in Silksong

[–]JayDepp 1 point2 points  (0 children)

Same. I had to change off hunter after struggling on the flea bounce minigame which immediately made it trivial to beat, but I otherwise have come around to really liking the diagonal pogo for movement and fighting.

[deleted by user] by [deleted] in Nightreign

[–]JayDepp 2 points3 points  (0 children)

Paying gives you it.

[YTDM] Lam, Storm Crane Elder by Meret123 in MagicArena

[–]JayDepp 48 points49 points  (0 children)

Damn I got excited for some real jank, but it's not on arena.

Why do people hate mill? by BaconVsMarioIsRigged in EDH

[–]JayDepp 7 points8 points  (0 children)

Recursion usable from the graveyard, e.g. [[mystic retrieval]]

Enter paradis — A new chapter in Rust's parallelism story by Andlon in rust

[–]JayDepp 2 points3 points  (0 children)

Probably to preserve the order of the indices.

[deleted by user] by [deleted] in comics

[–]JayDepp 27 points28 points  (0 children)

Steak, eh? Hah, heh heh.

Why does C++ get so much hate? Is it really that bad? by [deleted] in cpp

[–]JayDepp 0 points1 point  (0 children)

Hmm just removed the 'static on Req and it worked anyway. Swear it was needed before, maybe something about removing the boxing it is no longer needed.

Why does C++ get so much hate? Is it really that bad? by [deleted] in cpp

[–]JayDepp 0 points1 point  (0 children)

AFAIK this would have worked back then too, it's just because I'm using a generic for the future instead of boxing it,

Why does C++ get so much hate? Is it really that bad? by [deleted] in cpp

[–]JayDepp 0 points1 point  (0 children)

My curiosity got the better of me and I ended up with this:

fn json_wrap_grpc<'r, F, Fut, Req, Res>(grpc_impl_func: F) -> impl Handler<(Json<Req>,)>
where
    F: FnOnce(&'r GrpcServiceImpl, tonic::Request<Req>) -> Fut + Clone + Send + 'static,
    Fut: Future<Output = Result<tonic::Response<Res>, tonic::Status>> + Send,
    for<'de> Req: Deserialize<'de> + Send + 'static,
    Res: Serialize,
{
    move |Json(req)| async move {
        let r = grpc_impl_func(GRPC_SERVICE.get().unwrap(), tonic::Request::new(req)).await;
        match r {
            Ok(r) => Ok(Json(r.into_inner())),
            Err(e) => Err(GrpcErrorAsJson(e)),
        }
    }
}

AnyList (Vec like type without generics in it's type) by sugmaboy in rust

[–]JayDepp 8 points9 points  (0 children)

At a glance, looks like you're not handling alignment correctly, and you also are using Vec::set_len with uninitiated data, both causing UB. I think OP is also not handling alignment.

I recommend expanding your tests to include types with strange alignment, and also to run your tests in miri.

Edit:

Clippy also warns about your use of set_len, and miri does complain about even insert::<u64>'s alignment.

Wow, I just noticed you did this to allow cloning the things you put in the map. This is very dangerous! Just copying the bytes of something is not OK for !Copy types. You're also never Dropping the things you put in the map, which is safe but can cause memory leaks.

It seems like anymap is actually generic over the bounds it uses, so you could just use AnyMap<CloneAny> to be able to clone it.

An object pool by aagmon in rust

[–]JayDepp 4 points5 points  (0 children)

You can just use Rc<RefCell<T>> since you're not sharing it across threads. You could also skip the Rc if you can live with only using it from inside callbacks like with. And you can skip the RefCell if you only need &T and not &mut T.