You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: template.rs
    path of file: ./repos/cargo2nix/src
    
    the code of the file until where you have to start completion: use std::collections::BTreeMap;
use std::path::{Path, PathBuf};

use anyhow::{anyhow, Result};
use cargo::core::{dependency::DepKind, source::GitReference, Package, PackageId, SourceId};
use serde::Serialize;

use crate::manifest::TomlProfile;
use crate::{platform, BoolExpr, Feature as FeatureStr, Optionality, ResolvedPackage};

#[derive(Debug, Serialize)]
pub struct BuildPlan {
    pub cargo2nix_version: String,
    pub cargo_lock_hash: String,
    pub root_features: Vec<String>,
    pub profiles: BTreeMap<String, String>,
    pub workspace_members: Vec<Member>,
    pub crates: Vec<Crate>,
}

impl BuildPlan {
    pub fn from_items(
        cargo_lock_hash: String,
        root_pkgs: Vec<&'_ Package>,
        profiles: TomlProfile,
        rpkgs_by_id: BTreeMap<PackageId, ResolvedPackage<'_>>,
        cwd: &Path,
    ) -> Result<Self> {
        let root_features = root_pkgs
            .iter()
            .map(|pkg| format!("{}/default", pkg.name()))
            .collect();

        let profiles = profiles
            .into_iter()
            .map(|(name, profile)| (name, toml::to_string(&profile).unwrap()))
            .map(|(name, 
    
fn to_source(pkg: &ResolvedPackage<'_>, cwd: &Path) -> Result<Source> {
    let id = pkg.pkg.package_id();

    let source = if id.source_id().is_registry() {
        Source::CratesIo {
            sha256: pkg
                .checksum
                .as_ref()
                .map(|c| c.to_string())
                .ok_or(anyhow!("checksum is required for crates.io package {}", id))?,
        }
    } else if id.source_id().is_git() {
        let branch = if let Some(GitReference::Branch(branch)) = id.source_id().git_reference() {
            Some(branch.to_owned())
        } else {
            None
        };
        Source::Git {
            url: id.source_id().url().to_string(),
            rev: id
                .source_id()
                .precise()
                .map(|p| p.to_string())
                .ok_or(anyhow!("precise ref not found for git package {}", id))?,
            branch,
        }
    } else if id.source_id().is_path() {
        Source::Local {
            path: pathdiff::diff_paths(Path::new(id.source_id().url().path()), cwd)
                .map(|p| {
                    if p.to_string_lossy().len() == 0 {
                        p.join(".") // map degenerate empty path to "." for tera logic
                    } else {
                        p
                    }
                })
                .ok_or(anyhow!("path is not absolute for local package {}", id))?,
        }
    } else if id.source_id().is_registry() {
        Source::Registry {
            index: id.source_id().url().to_string(),
            sha256: pkg.checksum.as_ref().map(|c| c.to_string()).ok_or(anyhow!(
                "checksum is required for alternate registry package {}",
                id
            ))?,
        }
    } else {
        return Err(anyhow!("unsupported source for {}", id));
    };

    Ok(source)
}