lux_lib/tree/list.rs
1use std::collections::HashMap;
2
3use crate::{lockfile::LocalPackage, package::PackageName};
4
5use super::{Tree, TreeError};
6
7// TODO: Due to the whininess of the borrow checker, we resort to cloning package information
8// whenever returning it. In the future, it'd be greatly benefitial to instead return mutable
9// references to the packages, which would allow for in-place manipulation of the lockfile.
10// Cloning isn't destructive, but it's sure expensive.
11
12impl Tree {
13 pub fn list(&self) -> Result<HashMap<PackageName, Vec<LocalPackage>>, TreeError> {
14 Ok(self.lockfile()?.list())
15 }
16
17 pub fn as_rock_list(&self) -> Result<Vec<LocalPackage>, TreeError> {
18 let rock_list = self.list()?;
19
20 Ok(rock_list.values().flatten().cloned().collect())
21 }
22}