▲ 81 r/rust

What's the best way to tell the compiler that a path will basically never happen ?

I'm new to Rust, and my code has a part of it that uses a VecDeque filled with closures. It has a method that pops one and processes it. The last closure in that VecDeque ALWAYS contains code to add more closures to the deque. However, it starts out unpopulated, and requires the use of an initialize() method to actually get its first set of closures. As such, the only way the pop can return None is if it is used before initialization. The main function ensures this ́never does happen, because initialize() is always called before the first call of the processing method.

​

How can I tell the compiler that the None path will basically never happen ? I checked a bit and found the existence of unreachable\_unchecked and hint::cold. What would be the best ? Is there anything else I don't know about that's better ?

reddit.com
u/Krochire — 22 days ago
▲ 5 r/EmuDev

How does a Chip-8 handle reaching the end of it's memory ?

Hi everyone, first time emulator developer, and generally not that experienced programmer (I haven't taken what essentially corresponds to CS101 in my country's school system). I'm having doubts about implementing error checking on my program counter. For now, it's manipulated by these three functions implemented on a Cpu struct, which has an instance owned by a Chip8 struct (which is why I decided to expose functions instead of making the field pub, I'm not even sure this is idiomatic/good practice but I believe it to be):

    /// Change address of program counter.
    fn pc_change(&mut self, addr: usize) {
        assert!(
            addr < 0xfff,
            "Tried to move program counter at position {:#x}, it should be under 0xfff",
            self.pc
        );
        self.pc = addr;
    }

    /// Skip the next word.
    fn pc_skip(&mut self) {
        self.pc += 4;
        assert!(
            self.pc < 0xfff,
            "Program counter is at position {} after skip, it should be under 0xfff",
            self.pc
        );
    }

    /// Go to next word.
    fn pc_next(&mut self) {
        self.pc += 2;
        assert!(
            self.pc < 0xfff,
            "Program counter is at position {} after next, it should be under 0xfff",
            self.pc
        );
    }

For the people that don't know rust, this basically crashes if it ever goes over 0xffe (because if it was 0xfff, trying to read the word at that address would result in a panic anyways as there is no byte after it in my memory struct, and it'd say the index was 4096 but the length was 4096).

Is this what I should do ? Is there a better way ? I'm trying to do my best to make this run in an optimized way (which is hard as all my programming knowledge was gained from various reddit and stack overflow posts over the past year, because I'm too young to even get a basic python programming class, but I believe I'll manage it and will post my code for review once its first version is finished and polished).

reddit.com
u/Krochire — 1 month ago

At what point do you find a homebrew mechanic too complicated ?

First of all I know some of my friends may browse this sub, please look at my username!!! If you know me don't read or you'll get the whole campaign spoiled!!!

I'm currently making a megadungeon for my friend group inspired loosely by Lovecraft (I know, so original) and my own crippling thalassophobia.

I wanted the main focus to be the old headquarters/main temple of a pretty messed up cult that was consumed by their own search for power and had almost all of their members killed due to it. They searched it by going to gigantic creatures that dwell in the deepest parts of the sea, and asking them to perform spells for them in exchange for their own sanity, using their own language.

I obviously wanted to make this usable by players, so I started writing a rule addendum called "Benthic Magic". It isn't mature enough to share yet, but I'm afraid it'll become overcomplicated. For now and without going into details, I wanted to make an add-on to the DnD spell system that uses its own spell slots (referred to as Mental Sanity), and has spells cost more or less of those slots depending on their power instead of having levels to them. I also wanted a mechanic that would debuff players if they lose too much of it, because messing with your mind and all that.

Feel free to tell me what you would be reluctant to play with, both as a dm and a player! I'll show a first draft of the system made with Homebrewery in a few days.

reddit.com
u/Krochire — 1 month ago

Vouloir faire des choses autre que le web/l'IA en 2026, c'est une idée nulle ?

Je vais préfacer en disant que j'ai 16 ans et suis au lycée, donc j'ai le temps. Je stresse cependant beaucoup pour mon avenir.

Pour l'instant, mon idée, c'est spé maths/nsi > prépa MP2I/MPI > école d'ingé.

Problème étant que c'est avant tout un choix fait par passion la programmation, et que, peu importe où je regarde des offres d'emploi (je surveille le marché du travail pour être sûre de pas me gourer) c'est tout le temps les mêmes trucs qui recrutent des gens qui sortent d'école. "IA". "Développeur full stack". Je vais pas mentir que c'est pas des domaines qui m'intéresse énormément, et que ceux qui eux m'intéressent (genre l'embedded/systèmes) recrutent juste pas les gens qui ont pas d'expérience.

Du coup, la question que je pose à des gens qui sont eux vraiment sur le marché du travail c'est la suivante : est-ce que je vais vraiment pouvoir trouver un job sans avoir à toucher à ces domaines quand je serais plus grande ? Ou est-ce que je dois m'attendre à faire ça pendant un temps ?

reddit.com
u/Krochire — 2 months ago

This date seems really specific.

Couldn't they just have said "not defined" or something along those lines ?

Surely this isn't copium, we'll get news on either the dlc or the challenge quests coming back on/near this day, right ?

Surely...

u/Krochire — 2 months ago