Skip to content

reduce code redundancy for the encoding feature #262

@pchampin

Description

@pchampin

A lot of methods are defined twice in the code, once with encoding enabled, and once without it.
Some of these methods have different result types (direct value vs. Result), and this propagate to methods calling them (which must call the former with or without a ?, depending).
(NB: as pointed out in #180, only private method should have a change of signature, but this is orthogonal, I think)

I suggest the following change:

  • instead of returning T, private methods in the non-encoding configuration should return std::result::Result<T, std::convert::Infallible>, which after compilation is equivalent to T, but is syntactically is still a result.
  • Error should implement From<Infallible> (again, this is merely to please the compiler during parsing: the ‘from method will contain an unreachable!() statement, since Infallible has no value)
  • that way, all methods calling the private method can use ?, regardless of the presence/absence of the encoding feature. That way, they don't need two different implementation. The compiler will, however, ignore the ? when the underlying error type is Infallible (i.e. when encoding is disabled).

edited fixed the path of Infallible

Metadata

Metadata

Assignees

No one assigned

    Labels

    encodingIssues related to support of various encodings of the XML documentsenhancementhelp wanted

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions