rust

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDependencyRef

func ParseDependencyRef(dep string) (name, version string)

ParseDependencyRef parses a dependency reference string from Cargo.lock. Dependencies can be in formats: - "name" (simple, when only one version exists) - "name version" (when multiple versions might exist) - "name version (source)" (with explicit source)

Types

type CargoLock

type CargoLock struct {
	Version  int            `toml:"version"`
	Packages []LockPackage  `toml:"package"`
	Metadata toml.Primitive `toml:"metadata"` // Ignored but captured to avoid parse errors
}

CargoLock represents the structure of a Cargo.lock file.

func ParseCargoLock

func ParseCargoLock(dir string) (*CargoLock, error)

ParseCargoLock parses a Cargo.lock file from the given directory.

func ParseCargoLockData

func ParseCargoLockData(data []byte) (*CargoLock, error)

ParseCargoLockData parses Cargo.lock content from bytes.

func (*CargoLock) BuildPackageIndex

func (cl *CargoLock) BuildPackageIndex() (byKey map[PackageKey]*LockPackage, byName map[string][]*LockPackage)

BuildPackageIndex creates a map from package key to package for quick lookups. It also creates an index by name only for packages with unique names.

func (*CargoLock) FindRootPackages

func (cl *CargoLock) FindRootPackages() []*LockPackage

type CargoToml

type CargoToml struct {
	Package           PackageInfo               `toml:"package"`
	Dependencies      map[string]DependencySpec `toml:"dependencies"`
	DevDependencies   map[string]DependencySpec `toml:"dev-dependencies"`
	BuildDependencies map[string]DependencySpec `toml:"build-dependencies"`
	Target            map[string]TargetDeps     `toml:"target"`
	Workspace         *WorkspaceInfo            `toml:"workspace"`
}

CargoToml represents the structure of a Cargo.toml file.

func ParseCargoToml

func ParseCargoToml(dir string) (*CargoToml, error)

ParseCargoToml parses a Cargo.toml file from the given directory.

func ParseCargoTomlData

func ParseCargoTomlData(data []byte) (*CargoToml, error)

ParseCargoTomlData parses Cargo.toml content from bytes.

func (*CargoToml) GetDirectDependencies

func (ct *CargoToml) GetDirectDependencies() map[string]DependencyType

GetDirectDependencies returns a map of dependency names to their types. This includes dependencies from all sections and target-specific dependencies.

type CratesIOClient added in v0.2.1

type CratesIOClient struct {
	Agent   *khttp.Agent
	BaseURL string
}

CratesIOClient fetches crate metadata from the crates.io API.

func NewCratesIOClient added in v0.2.1

func NewCratesIOClient(concurrency int) *CratesIOClient

NewCratesIOClient creates a new client for the crates.io API.

func (*CratesIOClient) FetchAll added in v0.2.1

func (c *CratesIOClient) FetchAll(packages []PackageKey) map[PackageKey]*crateVersion

FetchAll fetches metadata for multiple crates in parallel using the Agent's GetGroup. Returns a map of PackageKey to parsed metadata. Errors on individual crates are silently skipped.

type Decomposer

type Decomposer struct{}

func New

func New() *Decomposer

func (*Decomposer) DefaultOptions

func (d *Decomposer) DefaultOptions() any

DefaultOptions returns the default options for the Rust decomposer.

func (*Decomposer) Extract

func (d *Decomposer) Extract(opts *api.DecomposerOptions) (*sbom.NodeList, error)

Extract parses Cargo.toml and Cargo.lock files and builds the complete dependency graph as a protobom NodeList.

func (*Decomposer) FindCodeBases

func (d *Decomposer) FindCodeBases(index *code.PathIndex) ([]string, error)

FindCodeBases locates Rust codebases by looking for Cargo.lock files.

func (*Decomposer) Requirements

func (d *Decomposer) Requirements(_ *api.DecomposerOptions) []api.Requirement

Requirements returns the requirements for the decomposer. No external binary required - uses pure Go implementation.

type DependencySpec

type DependencySpec struct {
	Version  string   `toml:"version"`
	Path     string   `toml:"path"`
	Git      string   `toml:"git"`
	Branch   string   `toml:"branch"`
	Tag      string   `toml:"tag"`
	Rev      string   `toml:"rev"`
	Features []string `toml:"features"`
	Optional bool     `toml:"optional"`
	// contains filtered or unexported fields
}

DependencySpec represents a dependency specification in Cargo.toml. Dependencies can be specified in multiple formats: - Simple: "1.0" - Table: { version = "1.0", features = ["foo"] }

func (*DependencySpec) GetVersion

func (ds *DependencySpec) GetVersion() string

GetVersion returns the version specification.

func (*DependencySpec) IsGit

func (ds *DependencySpec) IsGit() bool

IsGit returns true if this is a git dependency.

func (*DependencySpec) IsLocalPath

func (ds *DependencySpec) IsLocalPath() bool

IsLocalPath returns true if this is a path dependency.

func (*DependencySpec) UnmarshalTOML

func (ds *DependencySpec) UnmarshalTOML(data any) error

UnmarshalTOML implements custom unmarshaling for dependency specs.

type DependencyTree

type DependencyTree struct {
	// contains filtered or unexported fields
}

DependencyTree builds a complete dependency graph from Cargo files.

func NewDependencyTree

func NewDependencyTree(toml *CargoToml, lock *CargoLock, opts *Options) *DependencyTree

NewDependencyTree creates a new dependency tree from parsed Cargo files.

func (*DependencyTree) Build

func (dt *DependencyTree) Build(opts *api.DecomposerOptions) (*sbom.NodeList, error)

Build constructs the complete dependency graph as a protobom NodeList.

func (*DependencyTree) Enrich added in v0.2.1

func (dt *DependencyTree) Enrich(client *CratesIOClient)

Enrich fetches metadata from crates.io for all cached dependency nodes and populates license, description, homepage, repository, documentation, and other fields on the protobom nodes.

func (*DependencyTree) GetDependencyCount

func (dt *DependencyTree) GetDependencyCount() int

GetDependencyCount returns the total number of dependencies.

func (*DependencyTree) GetDirectDependencyCount

func (dt *DependencyTree) GetDirectDependencyCount() int

GetDirectDependencyCount returns the number of direct dependencies.

func (*DependencyTree) ListDependencies

func (dt *DependencyTree) ListDependencies() []string

ListDependencies returns a sorted list of all dependencies for debugging/testing.

type DependencyType

type DependencyType int

DependencyType represents the type of dependency relationship.

const (
	DepTypeNormal DependencyType = iota
	DepTypeDev
	DepTypeBuild
)

func (DependencyType) String

func (dt DependencyType) String() string

String returns a string representation of the dependency type.

type LockPackage

type LockPackage struct {
	Name         string   `toml:"name"`
	Version      string   `toml:"version"`
	Source       string   `toml:"source,omitempty"`
	Checksum     string   `toml:"checksum,omitempty"`
	Dependencies []string `toml:"dependencies,omitempty"`
}

LockPackage represents a package entry in Cargo.lock.

func ResolveDependency

func ResolveDependency(dep string, byKey map[PackageKey]*LockPackage, byName map[string][]*LockPackage) (*LockPackage, error)

ResolveDependency resolves a dependency reference to a specific package. If version is empty and multiple versions exist, it returns the first one found.

type Options

type Options struct {
	// IncludeDevDependencies includes dev dependencies in the output.
	IncludeDevDependencies bool

	// IncludeBuildDependencies includes build dependencies in the output.
	IncludeBuildDependencies bool

	// Concurrency controls the number of parallel HTTP requests to crates.io (default: 10).
	Concurrency int
}

Options configures the Rust dependency extraction.

type PackageInfo

type PackageInfo struct {
	Name        string `toml:"name"`
	Version     string `toml:"version"`
	Edition     string `toml:"edition"`
	Description string `toml:"description"`
	License     string `toml:"license"`
	Homepage    string `toml:"homepage"`
	Repository  string `toml:"repository"`
}

PackageInfo contains package metadata from Cargo.toml.

type PackageKey

type PackageKey struct {
	Name    string
	Version string
}

PackageKey uniquely identifies a package by name and version.

func (PackageKey) String

func (pk PackageKey) String() string

type TargetDeps

type TargetDeps struct {
	Dependencies      map[string]DependencySpec `toml:"dependencies"`
	DevDependencies   map[string]DependencySpec `toml:"dev-dependencies"`
	BuildDependencies map[string]DependencySpec `toml:"build-dependencies"`
}

TargetDeps represents target-specific dependencies.

type WorkspaceInfo

type WorkspaceInfo struct {
	Members      []string                  `toml:"members"`
	Dependencies map[string]DependencySpec `toml:"dependencies"`
}

WorkspaceInfo represents workspace configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL