Skip to content

IDNA API does not feel optimal when reusing Errors type #359

Closed as not planned
@SamWhited

Description

@SamWhited

Please pardon this slightly generic report; this isn't a specific issue per say, just an API concern (that may already have en easy fix and be my fault, or may be an API problem that would be harder to resolve):

Currently the uts46::Errors vec does not implement Eq or PartialEq, which makes sense since there are ordering concerns (is [Error1, Error2] the same as [Error2, Error1]?) which could potentially make the comparison more resource intense than expected.

However, this feels a bit poor when you're re-using errors in another API. For example, if I have a "dial" method that makes a TCP connection, I may want it to take an IP address or a domain. If it's a domain, it might perform the IDNA to_unicode operation and if it's an IP it might want to validate the format. In my package I would have an error enum like:

#[derive(Debug, Eq, PartialEq)]
pub enum Error {
    Addr(net::AddrParseError),
    IDNA(idna::uts46::Errors),
}

but now I can't define PartialEq for my errors struct (eg. if I want to do assert_eq! in tests). I could of course replace Errors with Error, but then I'd be losing information that users probably expect (since the IDNA package itself exposes all errors that occur during processing).

I suspect there's a way to make the Errors type nicer to reuse without implementing Eq/PartialEq, or I may just be missing something obvious that works today (in which case maybe better documentation is in order? Or maybe it's just me?). Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions