mz_ore/
env.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License in the LICENSE file at the
6// root of this repository, or online at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Process environment utilities.
17
18use std::env;
19use std::ffi::OsStr;
20
21/// Reports whether the environment variable `key` is set to a truthy value in
22/// the current process's environment.
23///
24/// The empty string and the string "0" are considered false. All other values
25/// are considered true.
26pub fn is_var_truthy<K>(key: K) -> bool
27where
28    K: AsRef<OsStr>,
29{
30    match env::var_os(key) {
31        None => false,
32        Some(val) => val != "0" && val != "",
33    }
34}