Skip to content

Handcraft many bundles at once#72

Open
Nadrieril wants to merge 2 commits intoalbertsgarde:mainfrom
Nadrieril:hand-craft-n
Open

Handcraft many bundles at once#72
Nadrieril wants to merge 2 commits intoalbertsgarde:mainfrom
Nadrieril:hand-craft-n

Conversation

@Nadrieril
Copy link
Copy Markdown
Contributor

Fixes #64. Based on #70 for the MultiBundle goodies.

@Nadrieril Nadrieril marked this pull request as ready for review February 24, 2026 21:31
@albertsgarde
Copy link
Copy Markdown
Owner

Looks good. Instead of creating a new craft_n function, could the HandCraft::craft function be modified? Specifically can this be done while allowing no worse an interface for single crafts. I don't mind backwards incompatibility

@Nadrieril
Copy link
Copy Markdown
Contributor Author

It could yeah, the only user change needed would be craft(..) -> craft::<1>(..). I don't think the amount will be inferrable unfortunately.

@albertsgarde
Copy link
Copy Markdown
Owner

Not inferrable, but it could default to 1 right? Think that would be a really nice interface

@Nadrieril
Copy link
Copy Markdown
Contributor Author

Rust doesn't allow defaults for const generics in functions unfortunately

@albertsgarde
Copy link
Copy Markdown
Owner

Fair enough. I thought I had used them on Territory::hand_mine, but clearly not. Also, apparently using const generic defaults and const expressions together can ICE the compiler, so it's really not an option.

@albertsgarde
Copy link
Copy Markdown
Owner

Just tried it out to test the ergonomics and ran into an issue. The relevant part of my save is

    let mut iron = iron_furnace.outputs(&tick).0.empty();
    let mut copper = copper_furnace.outputs(&tick).0.empty();
    let (wire1,) = CopperWireRecipe::craft(&mut tick, (copper.bundle().unwrap(),));
    let (wire2,) = CopperWireRecipe::craft_n::<5>(&mut tick, (copper.bundle().unwrap(),));

and on the last line I get

error[E0275]: overflow evaluating the requirement [(); rustorio_engine::::recipe::{impl#8}::{constant#0}] well-formed
--> src/bin/test3/main.rs:46:20
|
46 | let (wire2,) = CopperWireRecipe::craft_n::<5>(&mut tick, (copper.bundle().unwrap(),));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: required for (Bundle<CopperWire, 2>,) to implement rustorio_engine::recipe::MultiBundleMultiply<5>

I might look into it myself, but I don't have time at the moment.

@Nadrieril
Copy link
Copy Markdown
Contributor Author

Ah shoot, I hadn't actually tried using it ><

@albertsgarde
Copy link
Copy Markdown
Owner

lol. I was very close to just merging it, but stopped myself thinking I really should try it out first

@Nadrieril
Copy link
Copy Markdown
Contributor Author

Nadrieril commented Feb 26, 2026

I mean it will work if there's no inference at all, but here you're asking it to infer the bundle size and that's murky const generics shenanigans i didn't think of

@albertsgarde
Copy link
Copy Markdown
Owner

albertsgarde commented Feb 27, 2026

What is the intended usage?
I tried


    let (wire2,): (Bundle<CopperWire, 10>,) =
        CopperWireRecipe::craft_n::<5>(&mut tick, (copper.bundle::<5>().unwrap(),));

but got the same general error.

If even I can't immediately figure out usage we should at least include an example in the doc.

@Nadrieril
Copy link
Copy Markdown
Contributor Author

Oh, if that doesn't work then this is useless :(

@albertsgarde
Copy link
Copy Markdown
Owner

I'd love to have the feature if we can find some way to make it work. The error is specifically for checking a requirement, so maybe there's a way to change that to make it work.

@Nadrieril
Copy link
Copy Markdown
Contributor Author

Nadrieril commented Feb 28, 2026

I'm very confused, let _: (Bundle<CopperWire, 4>,) = CopperWireRecipe::craft_n::<2>(&mut tick, (bundle(),)); works for me. I added a test. Inferring the bundle size works...

@Nadrieril Nadrieril force-pushed the hand-craft-n branch 3 times, most recently from ac3c430 to 2667f5b Compare February 28, 2026 00:41
@albertsgarde
Copy link
Copy Markdown
Owner

I'm still getting the error.
My reproduction

#![forbid(unsafe_code)]
#![forbid(internal_features)]

use rustorio::{
    self, Bundle, HandRecipe, Tick,
    buildings::Furnace,
    gamemodes::Standard,
    recipes::{CopperSmelting, CopperWireRecipe},
    resources::{CopperWire, Point},
};

type GameMode = Standard;

type StartingResources = <GameMode as rustorio::GameMode>::StartingResources;

fn main() {
    rustorio::play::<GameMode>(user_main);
}

fn user_main(mut tick: Tick, starting_resources: StartingResources) -> (Tick, Bundle<Point, 200>) {
    let StartingResources {
        iron,
        mut iron_territory,
        mut copper_territory,
        steel_technology,
    } = starting_resources;

    let mut copper_furnace = Furnace::build(&tick, CopperSmelting, iron);

    let copper_ore = copper_territory.hand_mine::<20>(&mut tick);
    copper_furnace.inputs(&tick).0 += copper_ore;
    tick.advance_until(|tick| copper_furnace.inputs(tick).0 == 0);
    let mut copper = copper_furnace.outputs(&tick).0;
    let copper_bundle = copper.bundle::<5>().unwrap();
    let wire: (Bundle<CopperWire, 10>,) =
        CopperWireRecipe::craft_n::<5>(&mut tick, (copper_bundle,));

    todo!("Return the `tick` and the victory resources to win the game!")
}

As you can see I've attempted to specify everything to make the compiler's job as easy as possible, but I still get

overflow evaluating the requirement `[(); rustorio_engine::::recipe::{impl#9}::{constant#0}] well-formed`
required for `(rustorio::Bundle<rustorio::resources::CopperWire, 2>,)` to implement `rustorio_engine::recipe::MultiBundleMultiply<5>`

@Nadrieril Nadrieril force-pushed the hand-craft-n branch 2 times, most recently from 5e48785 to a03a0fe Compare March 2, 2026 22:30
@Nadrieril
Copy link
Copy Markdown
Contributor Author

Nadrieril commented Mar 2, 2026

Wow, this was rust-lang/rust#145069. Implemented the fix suggested there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HandCraft::craft should take a const generic stating how many to craft

2 participants