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

Remove RustCrateInlineModuleComposingWriter.kt #2456

Open
david-perez opened this issue Mar 14, 2023 · 0 comments
Open

Remove RustCrateInlineModuleComposingWriter.kt #2456

david-perez opened this issue Mar 14, 2023 · 0 comments
Labels
high-priority High priority issue refactoring Changes that do not affect our users, mostly focused on maintainability server Rust server SDK

Comments

@david-perez
Copy link
Contributor

In #2256, we introduced RustCrateInlineModuleComposingWriter.kt, containing utilities to render code in the same Rust module from different callsites in the code generator. This was done to enable constraint trait precedence, to render member shapes in the same module where the builder for the structure shape is hosted, all in the same model.rs file:

structure A {
    @length(max: 70)
    member: LengthString
}

structure B {
    @length(max: 70)
    member: LengthString
}

@length(max: 69)
string LengthString

Yields in model.rs:

struct A {
    member: a::Member
}

struct B {
    member: b::Member
}

pub mod a {
    struct Builder { ... }

    struct Member(pub(crate) String);
}

pub mod b {
    struct Builder { ... }

    struct Member(pub(crate) String);
}

In retrospect, this has had rippling effects throughout the codebase that make it more difficult to maintain. We could have dispensed with RustCrateInlineModuleComposingWriter, and it would have been simpler if we had just rendered each module in separate files:

model.rs:

struct A {
    member: a::Member
}

struct B {
    member: b::Member
}

a.rs:

struct Builder { ... }

struct Member(pub(crate) String);

b.rs:

struct Builder { ... }

struct Member(pub(crate) String);

This issue tracks the work needed to remove RustCrateInlineModuleComposingWriter. Note that now builders will go in a builders module as per #2455, so when tackling this issue one should keep that in mind.

@david-perez david-perez added server Rust server SDK refactoring Changes that do not affect our users, mostly focused on maintainability high-priority High priority issue labels Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high-priority High priority issue refactoring Changes that do not affect our users, mostly focused on maintainability server Rust server SDK
Projects
None yet
Development

No branches or pull requests

1 participant