fn from()

in crate_universe/src/parser.rs [264:324]


    fn from(cargo_toml: CargoToml) -> Value {
        let CargoToml {
            package,
            dependencies,
            build_dependencies,
            dev_dependencies,
            patch,
            _ignored,
        } = cargo_toml;

        let mut v = toml::value::Table::new();

        v.insert(String::from("package"), package.into());

        v.insert(
            String::from("lib"),
            toml::Value::Table({
                let mut table = toml::value::Table::new();
                // cargo-metadata fails without this key.
                table.insert(
                    String::from("path"),
                    toml::Value::String(String::from("doesnotexist.rs")),
                );
                table
            }),
        );

        if !dependencies.is_empty() {
            v.insert(
                String::from("dependencies"),
                table_of_dep_specs_to_toml(dependencies),
            );
        }
        if !build_dependencies.is_empty() {
            v.insert(
                String::from("build-dependencies"),
                table_of_dep_specs_to_toml(build_dependencies),
            );
        }
        if !dev_dependencies.is_empty() {
            v.insert(
                String::from("dev-dependencies"),
                table_of_dep_specs_to_toml(dev_dependencies),
            );
        }

        if !patch.is_empty() {
            v.insert(
                String::from("patch"),
                toml::Value::Table({
                    let mut table = toml::value::Table::new();
                    for (repo, patches) in patch {
                        table.insert(repo, table_of_dep_specs_to_toml(patches));
                    }
                    table
                }),
            );
        }

        toml::Value::Table(v)
    }