MicrodroidConfig: Unify API across flag configs
Flags should control the behavior of the code but using different APIs
with different flag configurations makes the code harder to reason about
when making a modification (in particular because flags configurations
aren't all tested at the same rate and a build breakage might be hard to
detect) so unfiy the different flag-defined "variants" of a same method
under a same signature.
In this process, improve the existing signatures:
- prefer "-> Option<&T>" over "-> &Option<T>" as it's easier to
generate, manipulate, and reason about
- prefer "-> &[T]" over "-> &Vec<T>" as it is more flexible, hiding an
implementation detail about the internal representation, and is
typically the recommended type to use in an API
Note: No functional change intended.
Test: banchan com.android.virt aosp_arm64 && m apps_only dist
Change-Id: I240d0bb0f1d6c630c89f2939261eed021912d01d
diff --git a/android/vm/src/main.rs b/android/vm/src/main.rs
index 6eee201..f2c2fa4 100644
--- a/android/vm/src/main.rs
+++ b/android/vm/src/main.rs
@@ -159,12 +159,12 @@
impl MicrodroidConfig {
#[cfg(vendor_modules)]
- fn vendor(&self) -> &Option<PathBuf> {
- &self.vendor
+ fn vendor(&self) -> Option<&PathBuf> {
+ self.vendor.as_ref()
}
#[cfg(not(vendor_modules))]
- fn vendor(&self) -> Option<PathBuf> {
+ fn vendor(&self) -> Option<&PathBuf> {
None
}
@@ -179,13 +179,13 @@
}
#[cfg(device_assignment)]
- fn devices(&self) -> &Vec<PathBuf> {
+ fn devices(&self) -> &[PathBuf] {
&self.devices
}
#[cfg(not(device_assignment))]
- fn devices(&self) -> Vec<PathBuf> {
- Vec::new()
+ fn devices(&self) -> &[PathBuf] {
+ &[]
}
}