pub trait EnvOverride: Sized {
const DEFAULT_ENV_NAME: &'static str;
// Required methods
fn parse_version(value: &str) -> Result<Self, ParseVersionError>;
fn detect_from_host() -> Result<Option<Self>, DetectVirtualPackageError>;
// Provided methods
fn parse_version_opt(
value: &str,
) -> Result<Option<Self>, DetectVirtualPackageError> { ... }
fn from_env_var_name_or<F>(
env_var_name: &str,
fallback: F,
) -> Result<Option<Self>, DetectVirtualPackageError>
where F: FnOnce() -> Result<Option<Self>, DetectVirtualPackageError> { ... }
fn detect_with_fallback<F>(
ov: &Override,
fallback: F,
) -> Result<Option<Self>, DetectVirtualPackageError>
where F: FnOnce() -> Result<Option<Self>, DetectVirtualPackageError> { ... }
fn detect(
ov: Option<&Override>,
) -> Result<Option<Self>, DetectVirtualPackageError> { ... }
}Expand description
Traits for overridable virtual packages
Use as Cuda::detect(override)
Required Associated Constants§
Sourceconst DEFAULT_ENV_NAME: &'static str
const DEFAULT_ENV_NAME: &'static str
Default name of the environment variable that overrides the virtual package.
Required Methods§
Sourcefn parse_version(value: &str) -> Result<Self, ParseVersionError>
fn parse_version(value: &str) -> Result<Self, ParseVersionError>
Parse env_var_value
Sourcefn detect_from_host() -> Result<Option<Self>, DetectVirtualPackageError>
fn detect_from_host() -> Result<Option<Self>, DetectVirtualPackageError>
Detect the virtual package for the current system.
This method is here so that <Self as EnvOverride>::current always
returns the same error type. current may return different types of
errors depending on the virtual package. This one always returns
DetectVirtualPackageError.
Provided Methods§
Sourcefn parse_version_opt(
value: &str,
) -> Result<Option<Self>, DetectVirtualPackageError>
fn parse_version_opt( value: &str, ) -> Result<Option<Self>, DetectVirtualPackageError>
Helper to convert the output of parse_version and handling empty
strings.
Sourcefn from_env_var_name_or<F>(
env_var_name: &str,
fallback: F,
) -> Result<Option<Self>, DetectVirtualPackageError>
fn from_env_var_name_or<F>( env_var_name: &str, fallback: F, ) -> Result<Option<Self>, DetectVirtualPackageError>
Read the environment variable and if it exists, try to parse it with
EnvOverride::parse_version If the output is:
None, then the environment variable did not exist,Some(Err(None)), then the environment variable exist but was set to zero, so the package should be disabledSome(Ok(pkg)), then the override was for the package.
Sourcefn detect_with_fallback<F>(
ov: &Override,
fallback: F,
) -> Result<Option<Self>, DetectVirtualPackageError>
fn detect_with_fallback<F>( ov: &Override, fallback: F, ) -> Result<Option<Self>, DetectVirtualPackageError>
Apply the override to the current virtual package. If the override is
None then use the fallback
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.