LCOV - code coverage report
Current view: top level - libs/utils/src - env.rs (source / functions) Coverage Total Hit
Test: fc67f8dc6087a0b4f4f0bcd74f6e1dc25fab8cf3.info Lines: 92.9 % 14 13
Test Date: 2024-09-24 13:57:57 Functions: 50.0 % 8 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      1263590 : pub fn var<V, E>(varname: &str) -> Option<V>
       6      1263590 : where
       7      1263590 :     V: FromStr<Err = E>,
       8      1263590 :     E: Display,
       9      1263590 : {
      10      1263590 :     match std::env::var(varname) {
      11      1262579 :         Ok(s) => Some(
      12      1262579 :             s.parse()
      13      1262579 :                 .map_err(|e| format!("failed to parse env var {varname}: {e:#}"))
      14      1262579 :                 .unwrap(),
      15      1262579 :         ),
      16         1011 :         Err(std::env::VarError::NotPresent) => None,
      17              :         Err(std::env::VarError::NotUnicode(_)) => {
      18            0 :             panic!("env var {varname} is not unicode")
      19              :         }
      20              :     }
      21      1263590 : }
        

Generated by: LCOV version 2.1-beta