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

Add Equatable Conformance to McuMgrTransportError #32

Open
nathanblamires opened this issue Jan 15, 2020 · 2 comments
Open

Add Equatable Conformance to McuMgrTransportError #32

nathanblamires opened this issue Jan 15, 2020 · 2 comments

Comments

@nathanblamires
Copy link
Contributor

It would be good to make McuMgrTransportError conform to equatable, so developers can easily test if certain errors are occurring and act accordingly. We added an extension in our app to do this, but others may have the same need so it would be good if it was apart of the standard framework. See code below.

extension McuMgrTransportError: Equatable {

    public static func == (lhs: McuMgrTransportError, rhs: McuMgrTransportError) -> Bool {
        switch (lhs, rhs) {
        case (.connectionTimeout, .connectionTimeout): return true
        case (.connectionFailed, .connectionFailed): return true
        case (.disconnected, .disconnected): return true
        case (.sendTimeout, .sendTimeout): return true
        case (.sendFailed, .sendFailed): return true
        case let (.insufficientMtu(lhsMTU), .insufficientMtu(rhsMTU)): return lhsMTU == rhsMTU
        case (.badResponse, .badResponse): return true
        default: return false
        }
    }
}
@bgiori
Copy link
Contributor

bgiori commented Jan 15, 2020

Hi Nathan, seems useful! Thanks for the heads up.

@tristandl
Copy link

if this protocol is added in an extension in the same file that the enum is declared (or protocol conformance specified on the type declaration itself) i don't think we can get a synthesised == method since the only associated value used is Int, which is already Equatable

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

No branches or pull requests

3 participants