LCOV - code coverage report
Current view: top level - libs/utils/src - env.rs (source / functions) Coverage Total Hit
Test: b4ae4c4857f9ef3e144e982a35ee23bc84c71983.info Lines: 57.1 % 14 8
Test Date: 2024-10-22 22:13:45 Functions: 37.5 % 8 3

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

Generated by: LCOV version 2.1-beta