rust

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindTestRegion added in v0.22.0

func FindTestRegion(content []byte) (startLine, endLine int, ok bool)

FindTestRegion returns the inclusive 1-indexed line range covering test-only code in a Rust source file. A test region is any item carrying an attribute that gates it to test builds:

  • `#[cfg(test)]`, `#[cfg(all(test, ...))]`, `#[cfg(any(test, ...))]` (and nested combinations), but NOT `#[cfg(not(test))]`
  • `#[test]`, `#[tokio::test]`, `#[async_std::test]`, `#[rstest]`, `#[test_case]`

Doctests inside `///` comments are NOT counted. Returns ok=false when no such region exists.

Known limitation: the item-end finder uses naive brace counting and does not strip string literals or `// }` comments. Hand-crafted Rust that places a `}` inside a string in the test region can mis-balance the count.

func IsTestFile

func IsTestFile(filePath string) bool

IsTestFile reports whether the given Rust path is a test file.

func IsTestFileWithContent

func IsTestFileWithContent(filePath string, contentReader vcs.ContentReader) bool

IsTestFileWithContent reports whether the given Rust path is a test file, using file content when available to confirm.

func ResolveRustProjectImports

func ResolveRustProjectImports(
	absPath string,
	filePath string,
	suppliedFiles map[string]bool,
	contentReader vcs.ContentReader,
) ([]string, error)

func SplitDiff added in v0.22.0

func SplitDiff(oldContent, newContent []byte, diff vcs.FileDiff) (prod, test vcs.FileStats)

SplitDiff attributes per-line additions and deletions to prod vs test using the test region found in oldContent (for deletions) and newContent (for additions). Either content may be nil/empty: oldContent is empty for new files; newContent is empty for deletions.

Types

type Module

type Module struct{}

func (Module) Extensions

func (Module) Extensions() []string

func (Module) IsTestFile

func (Module) IsTestFile(filePath string, contentReader vcs.ContentReader) bool

func (Module) Maturity

func (Module) Maturity() moduleapi.MaturityLevel

func (Module) Name

func (Module) Name() string

func (Module) NewResolver

func (Module) NewResolver(ctx *moduleapi.Context, contentReader vcs.ContentReader) moduleapi.Resolver

type PhantomDecision added in v0.22.0

type PhantomDecision struct {
	HasPhantom  bool
	ProdChanged bool
	ProdStats   vcs.FileStats
	TestStats   vcs.FileStats
}

PhantomDecision describes whether a Rust file should be rendered with a sibling "phantom" test node, and how additions/deletions split between the prod-side node and the phantom test node.

func DecidePhantomShow added in v0.22.0

func DecidePhantomShow(newContent []byte) PhantomDecision

DecidePhantomShow returns the phantom decision for `clarity show` (point-in- time) mode: the phantom is present iff newContent contains a test region.

func DecidePhantomWatch added in v0.22.0

func DecidePhantomWatch(oldContent, newContent []byte, diff vcs.FileDiff) PhantomDecision

DecidePhantomWatch returns the phantom decision for `clarity watch` (uncommitted) mode using the pre/post images and per-line diff. The phantom is present iff the test region has any additions or deletions.

type ProjectImportResolver added in v0.18.0

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

func NewProjectImportResolver added in v0.18.0

func NewProjectImportResolver(suppliedFiles map[string]bool, contentReader vcs.ContentReader) *ProjectImportResolver

func (*ProjectImportResolver) ResolveProjectImports added in v0.18.0

func (r *ProjectImportResolver) ResolveProjectImports(absPath string, filePath string) ([]string, error)

type RustImport

type RustImport struct {
	Path string
	Kind RustImportKind
}

RustImport represents a Rust import statement or module declaration.

func ParseRustImports

func ParseRustImports(sourceCode []byte) ([]RustImport, error)

ParseRustImports parses Rust source code and extracts imports.

func RustImports

func RustImports(filePath string) ([]RustImport, error)

RustImports parses a Rust file and returns its imports.

type RustImportKind

type RustImportKind int

RustImportKind describes the type of Rust import-like declaration.

const (
	RustImportUse RustImportKind = iota
	RustImportExternCrate
	RustImportModDecl
)

Jump to

Keyboard shortcuts

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