LCOV - code coverage report
Current view: top level - libs/utils/src - env.rs (source / functions) Coverage Total Hit
Test: d0feeceb9d5ee9c8e73bee7d4ffcced539793178.info Lines: 57.1 % 14 8
Test Date: 2024-06-26 15:19:01 Functions: 33.3 % 6 2

            Line data    Source code
       1              : //! Wrapper around `std::env::var` for parsing environment variables.
       2              : 
       3              : use std::{fmt::Display, str::FromStr};
       4              : 
       5          142 : pub fn var<V, E>(varname: &str) -> Option<V>
       6          142 : where
       7          142 :     V: FromStr<Err = E>,
       8          142 :     E: Display,
       9          142 : {
      10          142 :     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          142 :         Err(std::env::VarError::NotPresent) => None,
      17              :         Err(std::env::VarError::NotUnicode(_)) => {
      18            0 :             panic!("env var {varname} is not unicode")
      19              :         }
      20              :     }
      21          142 : }
        

Generated by: LCOV version 2.1-beta