LCOV - code coverage report
Current view: top level - libs/utils/src - env.rs (source / functions) Coverage Total Hit
Test: a43a77853355b937a79c57b07a8f05607cf29e6c.info Lines: 92.9 % 14 13
Test Date: 2024-09-19 12:04:32 Functions: 40.0 % 10 4

            Line data    Source code
       1              : //! Wrapper around `std::env::var` for parsing environment variables.
       2              : 
       3              : use std::{fmt::Display, str::FromStr};
       4              : 
       5      1268198 : pub fn var<V, E>(varname: &str) -> Option<V>
       6      1268198 : where
       7      1268198 :     V: FromStr<Err = E>,
       8      1268198 :     E: Display,
       9      1268198 : {
      10      1268198 :     match std::env::var(varname) {
      11      1267211 :         Ok(s) => Some(
      12      1267211 :             s.parse()
      13      1267211 :                 .map_err(|e| format!("failed to parse env var {varname}: {e:#}"))
      14      1267211 :                 .unwrap(),
      15      1267211 :         ),
      16          987 :         Err(std::env::VarError::NotPresent) => None,
      17              :         Err(std::env::VarError::NotUnicode(_)) => {
      18            0 :             panic!("env var {varname} is not unicode")
      19              :         }
      20              :     }
      21      1268198 : }
        

Generated by: LCOV version 2.1-beta