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

Unify the task source and task canceller API #21804

Merged
merged 2 commits into from Nov 16, 2018

Commits on Nov 13, 2018

  1. Implement TaskSource for HistoryTraversal

    And remove the method in window that returns it, because it isn't used
    so far.
    AgustinCB committed Nov 13, 2018

Commits on Nov 14, 2018

  1. Unify the task source and task canceller API

    I moved away from the `Window` struct all the logic to handle task
    sources, into a new struct called `TaskManager`. In a happy world, I'd
    be able to just have there two functions, of the types:
    
    ```rust
    fn task_source<T: TaskSource>(&self, name: TaskSourceName) -> Box<T>
    fn task_source_with_canceller<T: TaskSource>(&self, name: TaskSourceName)
      -> (Box<T>, TaskSourceCanceller)
    ```
    
    And not so much duplicated code. However, because TaskSource can't be a
    trait object (because it has generic type parameters), that's not
    possible. Instead, I decided to reduce duplicated logic through macros.
    
    For reasons[1], I have to pass both the name of the function with
    canceller and the name of the function without, as I'm not able to
    concatenate them in the macro itself. I could probably use
    `concat_idents` to create both types already defined and reduce the
    amount of arguments by one, but that macro is nightly only. At the same
    time, not being able to declare macros inside `impl` forces me to pass
    `self` as an argument.
    
    All this makes this solution more verbose than it would be ideally. It
    does reduce duplication, but it doesn't reduce the size of the file.
    
    [1](rust-lang/rust#29599)
    AgustinCB committed Nov 14, 2018
You can’t perform that action at this time.