Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't write code generically over CodeAssembler #231

Closed
Kixiron opened this issue Nov 30, 2021 · 3 comments · Fixed by #236
Closed

Can't write code generically over CodeAssembler #231

Kixiron opened this issue Nov 30, 2021 · 3 comments · Fixed by #236
Labels
enhancement New feature or request good first issue Good for newcomers Rust
Milestone

Comments

@Kixiron
Copy link
Contributor

Kixiron commented Nov 30, 2021

All of CodeAssembler's methods use generated traits (CodeAssembler::mov() has the CodeAsmMov trait, for instance) but these traits aren't public, making it impossible to write generic functions over an assembler, e.g.

struct MyCodeGenerator(CodeAssembler);

impl MyCodeGenerator {
    fn mov_but_better<T, U>(&mut self, dest: T, src: U) {
        self.0.mov(dest, 0);
        self.0.add(dest, src);
    }
}

These functions should be perfectly doable, but since the associated traits that act as bounds for the assembler methods aren't public there's no way to satisfy the bounds generically, causing compile errors

@wtfsck
Copy link
Member

wtfsck commented Dec 1, 2021

Yes that could be useful. Want to send a PR?

@wtfsck wtfsck added enhancement New feature or request good first issue Good for newcomers Rust labels Dec 1, 2021
@Kixiron
Copy link
Contributor Author

Kixiron commented Dec 2, 2021

Sure, could you point me where I should make this change?

@wtfsck
Copy link
Member

wtfsck commented Dec 2, 2021

Making one (or more?) of these pub will probably work, didn't test it.

mod fn_asm_impl;
mod fn_asm_pub;
mod fn_asm_traits;

@wtfsck wtfsck added this to the v1.16.0 milestone Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Rust
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants