LCOV - code coverage report
Current view: top level - libs/utils/src - env.rs (source / functions) Coverage Total Hit
Test: 20b6afc7b7f34578dcaab2b3acdaecfe91cd8bf1.info Lines: 57.1 % 14 8
Test Date: 2024-11-25 17:48:16 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