           raise "calling `cargo metadata` failed.\n" <> output
       end
 
-    json = Jason.decode!(metadata)
+    Jason.decode!(metadata)
+  end
 
-    packages = json["packages"]
-
+  defp external_resources(crate_path, crate, metadata) do
+    crate_str = to_string(crate)
+    packages = Map.fetch!(metadata, "packages")
     crate_spec = get_spec(packages, crate_str)
 
     packages

            priv_dir: "",
            skip_compilation?: false,
            target: nil,
            target_dir: ""

  alias Rustler.Compiler.Config


  end

  defp build(opts) do
    opts =
      if opts[:skip_compilation?] do
        opts
      else
        crate = Keyword.fetch!(opts, :crate)
        crate_path = Keyword.fetch!(opts, :path)

        metadata = metadata!(crate_path)
        resources = external_resources(crate_path, crate, metadata)

        opts
        |> Keyword.put(:metadata, metadata)
        |> Keyword.put(:external_resources, resources)
      end

    struct!(Config, opts)
  end

  defp metadata!(crate_path) do
    metadata =
      case System.cmd("cargo", ~w(metadata --format-version=1), cd: crate_path) do
        {metadata, 0} ->
