Skip to content

Refactor RelationshipResolver to use generic relationship types#14

Merged
hardbyte merged 3 commits intomainfrom
feat/generic-relationship
Feb 17, 2026
Merged

Refactor RelationshipResolver to use generic relationship types#14
hardbyte merged 3 commits intomainfrom
feat/generic-relationship

Conversation

@hardbyte
Copy link
Copy Markdown
Contributor

Summary

  • Make the relationship type in RelationshipResolver and RebacPolicy generic (Re) instead of hardcoded to &str
  • Allows using enums or other domain-specific types for compile-time safety
  • Add fmt::Display bound on Re for human-readable policy evaluation messages
  • Add enum-based relationship example to rebac_policy.rs

Based on @SteelAlloy's work in #11. Rebased on main (which now includes the #![warn(missing_docs)] changes from #13) and added the enum example requested in review.

Breaking change: RelationshipResolver<S, R> becomes RelationshipResolver<S, R, Re>, and RebacPolicy gains an additional type parameter.

Closes #10

Test plan

  • cargo fmt --all — no changes
  • cargo clippy --all-targets --all-features -- -D warnings — zero warnings
  • cargo doc --no-deps — zero warnings
  • cargo test --all-targets --all-features — all 65 tests pass
  • cargo test --doc — all 9 doc tests pass
  • cargo run --example rebac_policy — runs successfully including new enum section

Make the relationship type in RelationshipResolver and RebacPolicy
generic instead of hardcoded to &str. This allows using enums or
other domain-specific types for compile-time safety — a typo like
"contibutor" becomes a compile error rather than a silent permission
failure.

Add an enum-based relationship example to rebac_policy.rs demonstrating
the pattern.

Co-authored-by: Steel <52361520+SteelAlloy@users.noreply.github.com>
Closes #10
Copilot AI review requested due to automatic review settings February 17, 2026 00:44
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e71597e24

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors RelationshipResolver and RebacPolicy to use a generic relationship type parameter (Re) instead of hardcoded &str, enabling compile-time safety when using enums or other domain-specific types for relationships. This addresses issue #10 by allowing strongly-typed relationship definitions.

Changes:

  • Added generic type parameter Re to RelationshipResolver trait and RebacPolicy struct
  • Added fmt::Display bound on Re for human-readable policy evaluation messages
  • Updated all existing implementations to use String as the relationship type
  • Added comprehensive enum-based relationship example demonstrating type-safe alternative to strings

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/lib.rs Adds generic Re type parameter to RelationshipResolver trait and RebacPolicy, updates documentation and tests to use String explicitly
examples/rebac_policy.rs Updates string-based examples to use .to_string() and adds new enum-based relationship example with Display implementation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Document that Re must implement Display (used for human-readable
policy evaluation reasons). Fix enum example output that said
"viewer" when Bob is actually a contributor.
- Move Display requirement docs from RelationshipResolver trait (where
  it is not enforced) to RebacPolicy struct (where the bound lives)
- Remove redundant Send + Sync bounds on RG in Policy impl (already
  required by RelationshipResolver supertrait)
- Add unit test for enum-based relationship types
- Fix enum example: test all three users, correct comment to say
  "only owners can edit", add assertions
Copilot AI review requested due to automatic review settings February 17, 2026 01:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hardbyte hardbyte merged commit f459ab6 into main Feb 17, 2026
8 checks passed
@hardbyte hardbyte deleted the feat/generic-relationship branch February 17, 2026 01:52
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.

RelationshipResolver should allow broader relationship than str

2 participants