Skip to content

Flattened struct helper functions#273

Open
Exotik850 wants to merge 9 commits into
Bergmann89:masterfrom
Exotik850:flattened-functions
Open

Flattened struct helper functions#273
Exotik850 wants to merge 9 commits into
Bergmann89:masterfrom
Exotik850:flattened-functions

Conversation

@Exotik850
Copy link
Copy Markdown

Add flattened content helpers render step

This PR introduces the FlattenedContentHelpersRenderStep which generates ergonomic helper accessor methods for flattened struct content patterns (e.g., pub struct Foo { pub content: Vec<FooContent>, ... } with pub enum FooContent { ... }). The step creates methods like fn bar(&self) -> Option<&String> and mutable variants thereof for each enum variant, improving usability of generated code.

Changes include:

  • New render step implementation in src/pipeline/renderer/steps/flattened.rs
  • Adds the step to the publicly available render steps
  • Test case verifying generated helper methods for a sample schema

The feature is enabled via the renderer configuration and follows the existing pattern for optional render steps

e.g.

Config::default().with_render_step(FlattenedContentHelpersRenderStep)

Copy link
Copy Markdown
Owner

@Bergmann89 Bergmann89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, nice work 👍
Some smaller things that need to be cleaned up, then this can be merged 🙃

Comment thread xsd-parser/src/pipeline/renderer/steps/flattened.rs Outdated
Comment thread xsd-parser/src/pipeline/renderer/steps/flattened.rs Outdated
Comment thread xsd-parser/src/pipeline/renderer/steps/content_helper.rs
Comment thread xsd-parser/src/pipeline/renderer/steps/content_helper.rs Outdated
Comment thread xsd-parser/src/pipeline/renderer/steps/flattened.rs Outdated
Copy link
Copy Markdown
Owner

@Bergmann89 Bergmann89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing you forgot to revert 🙃

/// List of keywords that needs to be replaced by something else.
/// This list needs to be sorted, because we use it in [`core::slice::binary_search_by`]
const KEYWORDS: &[(&str, &str)] = &[
pub(crate) const KEYWORDS: &[(&str, &str)] = &[
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we now use the already prepared field_ident we don't need to export this.

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.

2 participants