Repository: astral-sh/uv
File: crates/uv/src/commands/pip/loggers.rs (Rust)

Code before:
            .chain(changelog.installed.iter().map(|distribution| ChangeEvent {
                dist: distribution,
                kind: ChangeEventKind::Added,
            }))
            .chain(
                changelog
                    .reinstalled
                    .iter()
                    .map(|distribution| ChangeEvent {
                        dist: distribution,
                        kind: ChangeEventKind::Reinstalled,
                    }),
            )
            .sorted_unstable_by(|a, b| {
                a.dist
                    .name()
                    .cmp(b.dist.name())
                    .then_with(|| a.kind.cmp(&b.kind))
                    .then_with(|| a.dist.installed_version().cmp(&b.dist.installed_version()))
            })
        {
            let version = event
                .dist
                .installed_version()
                .map(|v| v.to_string())
                .unwrap_or_else(|| "unknown".to_string());
            match event.kind {
                ChangeEventKind::Added => {
                    writeln!(
                        printer.stderr(),
                        " {} {}{}",
                        "+".green(),
                        event.dist.name().bold(),
                        version.dimmed(),
                    )?;
                }
                ChangeEventKind::Removed => {
                    writeln!(
                        printer.stderr(),
                        " {} {}{}",
                        "-".red(),
                        event.dist.name().bold(),
                        version.dimmed(),
                    )?;
                }
                ChangeEventKind::Reinstalled => {
                    writeln!(
                        printer.stderr(),
                        " {} {}{}",
                        "~".yellow(),
                        event.dist.name().bold(),

Review comment (suggestion):
This now allocates unfortunately. Let me know if there's a straightforward way to avoid this (I am aware of `either` being probably usable here, but I didn't want to add dependencies - although it is used elsewhere).

Code after:
            "{}",
            if dry_run.enabled() {
                format!("Would uninstall {what}")
            } else {
                format!(
                    "Uninstalled {what} {}",
                    format!("in {}", elapsed(start.elapsed())).dimmed()
                )
            }
            .dimmed()
        )
    }

    fn on_install(
        &self,
        count: usize,
        start: std::time::Instant,
        printer: Printer,
        dry_run: DryRun,
    ) -> fmt::Result {
        let s = if count == 1 { "" } else { "s" };
        let what = format!("{count} package{s}");
        let what = what.bold();
        writeln!(
            printer.stderr(),
            "{}",
            if dry_run.enabled() {
                format!("Would install {what}")
            } else {
                format!(
                    "Installed {what} {}",
                    format!("in {}", elapsed(start.elapsed())).dimmed()
                )
            }
            .dimmed()
        )
    }

    fn on_complete(
        &self,
        changelog: &Changelog,
        printer: Printer,
        _dry_run: DryRun,
    ) -> fmt::Result {
        for event in changelog
            .uninstalled
            .iter()
            .map(|distribution| ChangeEvent {
                dist: distribution,
                kind: ChangeEventKind::Removed,
            })