rust: Refactor staticStd to stdLinkage

Instead of returning a boolean, return an enum value to improve
readability and provide greater flexibility for future modifications.

Bug: 168729404
Test: Soong tests pass
Change-Id: Iddcdae8c34be09e476404382e43d1ea5935bae65
diff --git a/rust/binary.go b/rust/binary.go
index e95cb3a..2758ae0 100644
--- a/rust/binary.go
+++ b/rust/binary.go
@@ -145,6 +145,9 @@
 	}
 }
 
-func (binary *binaryDecorator) staticStd(ctx *depsContext) bool {
-	return binary.baseCompiler.staticStd(ctx) || Bool(binary.Properties.Prefer_rlib)
+func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
+	if Bool(binary.Properties.Prefer_rlib) {
+		return RlibLinkage
+	}
+	return binary.baseCompiler.stdLinkage(ctx)
 }
diff --git a/rust/compiler.go b/rust/compiler.go
index aeb904b..102f9dc 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -24,6 +24,14 @@
 	"android/soong/rust/config"
 )
 
+type RustLinkage int
+
+const (
+	DefaultLinkage RustLinkage = iota
+	RlibLinkage
+	DylibLinkage
+)
+
 func (compiler *baseCompiler) edition() string {
 	return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition)
 }
@@ -146,12 +154,12 @@
 	panic("baseCompiler does not implement coverageOutputZipPath()")
 }
 
-func (compiler *baseCompiler) staticStd(ctx *depsContext) bool {
+func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage {
 	// For devices, we always link stdlibs in as dylibs by default.
 	if ctx.Device() {
-		return false
+		return DylibLinkage
 	} else {
-		return true
+		return RlibLinkage
 	}
 }
 
diff --git a/rust/library.go b/rust/library.go
index 2792c5b..7a77706 100644
--- a/rust/library.go
+++ b/rust/library.go
@@ -158,9 +158,12 @@
 	return library.MutatedProperties.VariantIsStatic
 }
 
-func (library *libraryDecorator) staticStd(ctx *depsContext) bool {
-	// libraries should only request the staticStd when building a static FFI or when variant is staticStd
-	return library.static() || library.MutatedProperties.VariantIsStaticStd
+func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
+	// libraries should only request the RlibLinkage when building a static FFI or when variant is StaticStd
+	if library.static() || library.MutatedProperties.VariantIsStaticStd {
+		return RlibLinkage
+	}
+	return DefaultLinkage
 }
 
 func (library *libraryDecorator) source() bool {
diff --git a/rust/rust.go b/rust/rust.go
index 22b81f1..f88b310 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -294,7 +294,7 @@
 	Disabled() bool
 	SetDisabled()
 
-	staticStd(ctx *depsContext) bool
+	stdLinkage(ctx *depsContext) RustLinkage
 }
 
 type exportedFlagsProducer interface {
@@ -997,8 +997,9 @@
 		commonDepVariations = append(commonDepVariations,
 			blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
 	}
+
 	stdLinkage := "dylib-std"
-	if mod.compiler.staticStd(ctx) {
+	if mod.compiler.stdLinkage(ctx) == RlibLinkage {
 		stdLinkage = "rlib-std"
 	}
 
@@ -1030,7 +1031,7 @@
 		}
 	}
 	if deps.Stdlibs != nil {
-		if mod.compiler.staticStd(ctx) {
+		if mod.compiler.stdLinkage(ctx) == RlibLinkage {
 			actx.AddVariationDependencies(
 				append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}),
 				rlibDepTag, deps.Stdlibs...)
diff --git a/rust/test.go b/rust/test.go
index 0679448..bc7f53c 100644
--- a/rust/test.go
+++ b/rust/test.go
@@ -134,6 +134,6 @@
 	return module.Init()
 }
 
-func (test *testDecorator) staticStd(ctx *depsContext) bool {
-	return true
+func (test *testDecorator) stdLinkage(ctx *depsContext) RustLinkage {
+	return RlibLinkage
 }