Function memory_config_check

Source
pub fn memory_config_check(
    memory_config: &MemoryConfig,
) -> Result<Option<(String, u64)>, MemoryConfigError>
Expand description

Checks a specified environment variable against a configured minimum and maximum values.

This function is used at application startup to verify that a system memory setting (MALLOC_ARENA_MAX) is within a safe and expected range.

§Arguments

  • memory_config - A reference to the MemoryConfig struct containing the check parameters (active flag, variable name, min/max values).

§Returns

A Result containing an Option on success:

  • Ok(Some((String, u64))): If the check is active and the environment variable’s value is within the configured bounds. The tuple contains the variable’s name and its parsed value.
  • Ok(None): If the check is configured to be inactive (active: false).

§Errors

Returns a MemoryConfigError if the check is active and any validation step fails:

  • MemoryConfigError::ConfigEnvVarNameEmpty: If active is true, but the env_variable_name in the configuration is empty.
  • MemoryConfigError::EnvVarNotSet: If the specified environment variable is not set in the current environment.
  • MemoryConfigError::EnvVarParseError: If the value of the environment variable cannot be parsed into a u64 integer.
  • MemoryConfigError::EnvVarValueTooLow: If the parsed value is less than the configured env_variable_min_val.
  • MemoryConfigError::EnvVarValueTooHigh: If the parsed value is greater than the configured env_variable_max_val.