Skip to main content

servers_from_env_var

Function servers_from_env_var 

Source
pub fn servers_from_env_var(
    var_name: &str,
    default: &str,
) -> Result<Vec<ServerAddr>, String>
Expand description

Parses a comma-separated NATS server list from an environment variable.

Each entry is trimmed and empty entries are ignored, so a trailing comma is harmless. default is parsed the same way when the variable is unset (or not valid Unicode). A variable that is set but empty is not replaced by default.

§Arguments

  • var_name - Name of the environment variable to read, for example NATS_SERVERS. Also used in error messages.
  • default - Comma-separated server list used when the variable is unset.

§Returns

The parsed server addresses, in the order given.

§Errors

Returns an error message if any entry cannot be parsed as a [ServerAddr], or if no non-empty entries remain.