pub fn sort(&self) -> Option<PackageSet> {
        let mut graph = graph::Graph::new();

        for pkg in self.packages.iter() {
            let deps: Vec<&str> = pkg.dependencies().iter()
                .map(|dep| dep.name())
                .collect();

            graph.add(pkg.name(), &deps);
        }

        let pkgs = match graph.sort() {
            Some(pkgs) => pkgs,
            None => return None,
        };
        let pkgs = pkgs.iter().map(|name| {
            self.get(*name).clone()
        }).collect();

        Some(PackageSet {
            packages: pkgs
        })
    }
// For now, assume that the package set contains only one package with a
// given name
For now, assume that the package set contains only one package with a
given name
For now assume that the package set contains only one package with a given name
pub fn sort(&self) -> Option<PackageSet> {
        let mut graph = graph::Graph::new();
        for pkg in self.packages.iter() {
            let deps: Vec<&str> = pkg.dependencies().iter()
                .map(|dep| dep.name())
                .collect();
            graph.add(pkg.name(), &deps);
        }
        let pkgs = match graph.sort() {
            Some(pkgs) => pkgs,
            None => return None,
        };
        let pkgs = pkgs.iter().map(|name| {
            self.get(*name).clone()
        }).collect();
        Some(PackageSet {
            packages: pkgs
        })
    }
pub fn sort ( & self ) -> Option < PackageSet > { let mut graph = graph :: Graph :: new ( ) ; for pkg in self . packages . iter ( ) { let deps : Vec < & str > = pkg . dependencies ( ) . iter ( ) . map ( | dep | dep . name ( ) ) . collect ( ) ; graph . add ( pkg . name ( ) , & deps ) ; } let pkgs = match graph . sort ( ) { Some ( pkgs ) => pkgs , None => return None , } ; let pkgs = pkgs . iter ( ) . map ( | name | { self . get ( * name ) . clone ( ) } ) . collect ( ) ; Some ( PackageSet { packages : pkgs } ) }
For now, assume that the package set contains only one package with a
given name
For now assume that the package set contains only one package with a given name
&self
&self