LCOV - code coverage report
Current view: top level - libs/utils/src - env.rs (source / functions) Coverage Total Hit
Test: 2e3a7638747e564a4f6d1af1cc0c3b3438fbb740.info Lines: 57.1 % 14 8
Test Date: 2024-11-20 01:36:58 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          339 : pub fn var<V, E>(varname: &str) -> Option<V>
       6          339 : where
       7          339 :     V: FromStr<Err = E>,
       8          339 :     E: Display,
       9          339 : {
      10          339 :     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          339 :         Err(std::env::VarError::NotPresent) => None,
      17              :         Err(std::env::VarError::NotUnicode(_)) => {
      18            0 :             panic!("env var {varname} is not unicode")
      19              :         }
      20              :     }
      21          339 : }
        

Generated by: LCOV version 2.1-beta