add implement the Hashable & Equatable to SmartIgnored#113
Conversation
WalkthroughAdded conditional Equatable and Hashable conformances to the SmartIgnored property wrapper by delegating comparison and hashing to wrappedValue when T meets those protocols. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
Sources/SmartCodable/Core/PropertyWrapper/SmartIgnored.swift (1)
71-75: LGTM: Hashable conformance; minor nitsImplementation is correct. Two small nits:
- Verify that excluding
isEncodablefrom hashing is intentional.- Consider marking these tiny methods
@inlinablefor cross‑module performance, or movepublicto the extension (public extension) for consistency.Apply if you agree:
-extension SmartIgnored: Equatable where T: Equatable { - public static func == (lhs: Self, rhs: Self) -> Bool { +public extension SmartIgnored where T: Equatable { + @inlinable + static func == (lhs: Self, rhs: Self) -> Bool { return lhs.wrappedValue == rhs.wrappedValue } } -extension SmartIgnored: Hashable where T: Hashable { - public func hash(into hasher: inout Hasher) { +public extension SmartIgnored where T: Hashable { + @inlinable + func hash(into hasher: inout Hasher) { wrappedValue.hash(into: &hasher) } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
Sources/SmartCodable/Core/PropertyWrapper/SmartIgnored.swift(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
Sources/SmartCodable/Core/PropertyWrapper/SmartIgnored.swift (1)
65-69: LGTM: Equatable conformance via wrappedValue; confirm synthesized semantics on ownersThis is correct and unblocks synthesized Equatable on types containing
@SmartIgnored. Note this makes the wrapped value participate in owners’ synthesized equality; confirm that’s the intended behavior for an “ignored” property (ignore only for coding, not for identity).
|
V5.1.3已支持 |
问题
在使用
NSDiffableDataSourceSnapshot时,snapshot要求Item遵守Hashable协议,假如Item中的某个属性被@SmartIgnored标记,会因为@SmartIgnored未实现Hashable协议而编译失败。当然使用者也可以自己解决,比如不用
@SmartIgnored, 或者项目中自己对SmartIgnored添加Hashableextetion。不过我感觉这是一个比较常见的业务场景,所以提了这个MR。Code
Summary by CodeRabbit