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

Support dyn Progress #21

Closed
NobodyXu opened this issue Aug 19, 2023 · 1 comment · Fixed by #22
Closed

Support dyn Progress #21

NobodyXu opened this issue Aug 19, 2023 · 1 comment · Fixed by #22

Comments

@NobodyXu
Copy link
Contributor

NobodyXu commented Aug 19, 2023

I would like to add another provided method to Progress, suitable for trait-object usage to avoid monomorphization:

triat DynProgress: Send + Sync {
    // Required methods
    fn add_child(&mut self, name: String) -> BoxedDynProgress;
    fn add_child_with_id(
        &mut self,
        name: String,
        id: Id
    ) -> BoxedDynProgress;
    fn init(&mut self, max: Option<Step>, unit: Option<Unit>);
    fn set(&mut self, step: Step);
    fn step(&self) -> Step;
    fn inc_by(&mut self, step: Step);
    fn set_name(&mut self, name: String);
    fn name(&self) -> Option<String>;
    fn id(&self) -> Id;
    fn message(&self, level: MessageLevel, message: String);

    // Provided methods
    fn unit(&self) -> Option<Unit> { ... }
    fn max(&self) -> Option<Step> { ... }
    fn set_max(&mut self, _max: Option<Step>) -> Option<Step> { ... }
    fn inc(&mut self) { ... }
    fn counter(&self) -> Option<StepShared> { ... }
    fn info(&self, message: String) { ... }
    fn done(&self, message: String) { ... }
    fn fail(&self, message: String) { ... }
    fn show_throughput(&self, start: Instant) { ... }
    fn show_throughput_with(
        &self,
        start: Instant,
        step: Step,
        unit: Unit,
        level: MessageLevel
    ) { ... }
}

/// An opaque type so that `gix` can internally change its implementation details,
/// e.g. use an `Arc` instead of `Box`, or even inlining the progress.
pub struct BoxedDynProgress;

impl BoxedDynProgress {
    pub fn new<P: Progress>(p: P) -> Self;
}

impl DynProgress for BoxedDynProgress {
    // ...
}

impl Progress for BoxedDynProgress {
    type SubProgress = Self;

    // ...
}

trait Progress {
    // ...

    // Provided method
    fn into_dyn_progressive(&mut self) -> DynProgressRef<&mut Self>;
}

pub struct DynProgressRef<'_, T>;

Originally posted on GitoxideLabs/gitoxide#987

NobodyXu added a commit to NobodyXu/prodash that referenced this issue Aug 19, 2023
Fixed Byron#21

`DynProgress` is sealed and implemented for any type that implements
`Progress`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
@Byron
Copy link
Owner

Byron commented Aug 19, 2023

As we are aligned with what to generally do, I think it's absolutely OK to skip issues and go right for PRs. They are easier to work with as well thanks to actual code being available. If that's OK with you, please feel free to close this in favor of the PR.

@Byron Byron closed this as completed in 24d0b2a Sep 4, 2023
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

Successfully merging a pull request may close this issue.

2 participants