Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

ErrorHandler should wrap parser, not the other way around #439

Open
jyn514 opened this issue May 19, 2020 · 0 comments
Open

ErrorHandler should wrap parser, not the other way around #439

jyn514 opened this issue May 19, 2020 · 0 comments

Comments

@jyn514
Copy link
Owner

jyn514 commented May 19, 2020

Currently, the error_handler is always a field of whatever struct it's on, like this:

struct ErrorHandler { errors: ... }
struct Parser {
    error_handler: ErrorHandler,
    // ...
}

This Is the traditional way to do pseudo-inheritance in Rust, through composition. However, it means that all the relevant methods have to be re-written since the field is not public. As an alternative, @Nemo157 suggested instead that the struct be wrapped by the error handler, the same way Locatable works:

struct Parser;
struct ErrorHandler<T> {
    inner: T,
    errors: ...
}

This means the methods for the error handler no longer have to be rewritten for each new struct.

cc @pythondude325

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant