Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseDependencyRef ¶
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 ¶
ParseCargoLock parses a Cargo.lock file from the given directory.
func ParseCargoLockData ¶
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 ¶
ParseCargoToml parses a Cargo.toml file from the given directory.
func ParseCargoTomlData ¶
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 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) *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) 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
}
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 ¶
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.