Skip to content

Allow for custom traits - #6

Open
kaimast wants to merge 3 commits into
decomoraes:mainfrom
kaimast:custom-traits
Open

Allow for custom traits#6
kaimast wants to merge 3 commits into
decomoraes:mainfrom
kaimast:custom-traits

Conversation

@kaimast

@kaimast kaimast commented Apr 10, 2024

Copy link
Copy Markdown

I took a stab at #5 and added an example. Let me know what you think! I also re-organized the top-level Cargo.toml a little to make examples work correctly.

@decomoraes

Copy link
Copy Markdown
Owner

Hello @kaimast, thank you for your contribution. I will check it as soon as possible.

@decomoraes

Copy link
Copy Markdown
Owner

Hello @kaimast,
Thank you for your pull request. After carefully reviewing the proposed changes, I have concerns regarding backward compatibility. The introduction of a specific type Item would result in breaking changes for existing users of the library. Code relying on the current implementation, which utilizes dyn Any for maximum flexibility, would need to be significantly modified to adapt to the new approach. For instance:

if let Some(string_opt) = value.downcast_ref::<Option<String>>() {
    if let Some(string) = string_opt.as_deref() {
        return Some((key.to_string(), format!("{}", string)));
    }
}

This snippet would no longer work as intended, affecting users' existing code. To preserve backward compatibility while adopting your suggested improvements, I'm considering introducing a new trait, IterableItem, alongside the existing Iterable trait. This way, we avoid breaking changes for current users. Could you adjust your PR to fit this dual-trait approach?

Looking forward to your thoughts.

@kaimast

kaimast commented Jun 27, 2024

Copy link
Copy Markdown
Author

Sorry for the delay. Could you take a look at the example I added ("examples/any.rs"). I think what you describe still works.

The only difference is that the generated trait now has an Item field. I can add a separate trait like you suggested, but it would introduce some code duplication.

Also, I would suggest adding basic CI to the repository so that pull requests can be tested. I can make another pull request that adds Github Actions if you want.

decomoraes pushed a commit that referenced this pull request Jul 3, 2026
…e drafts

- README rewritten for 0.2.0: no_std/zero-alloc pitch, mutation and
  custom-trait-object sections with compiling examples, updated
  comparison table, and a 'Migrating from 0.1' table leading with 'the
  common path needs no changes'
- CHANGELOG 0.2.0 entry: additions, explicit Breaking items, credit
  lines for @mjhouse (#3/#4), @kaimast (#6) and @srid (#5), fixed-issue
  links, migration table
- release-plz config + workflow (lockstep version_group, semver_check,
  single v{version} tag; release job inert until CARGO_REGISTRY_TOKEN
  is configured); CONTRIBUTING release section documents the PR flow
  and the manual publish order derive -> facade -> internal (the shim
  now depends on the facade, so it goes last)
- docs/maintainer/triage-drafts.md: ready-to-paste comments for issues
  #1/#2/#5/#7 and PR #6, a pinned roadmap issue draft, and a
  publish-day checklist — nothing is posted automatically
- new custom_trait example; config_validation now also shows field_mut

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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