Update env_var_to_ffi() to take an Option<EnvVar>

It wasn't possible to handle cases where vars.get() returned `None` then forward
that to C++, but now we can.
This commit is contained in:
Mahmoud Al-Qudsi 2023-05-16 20:11:05 -05:00
parent 32912b6525
commit cce78eeb43
2 changed files with 7 additions and 3 deletions

View file

@ -34,8 +34,12 @@ lazy_static! {
static UVARS_LOCALLY_MODIFIED: RelaxedAtomicBool = RelaxedAtomicBool::new(false);
/// Convert an EnvVar to an FFI env_var_t.
fn env_var_to_ffi(var: EnvVar) -> cxx::UniquePtr<ffi::env_var_t> {
ffi::env_var_t::new_ffi(Box::into_raw(Box::from(var)).cast()).within_unique_ptr()
pub fn env_var_to_ffi(var: Option<EnvVar>) -> cxx::UniquePtr<ffi::env_var_t> {
if let Some(var) = var {
ffi::env_var_t::new_ffi(Box::into_raw(Box::from(var)).cast()).within_unique_ptr()
} else {
cxx::UniquePtr::null()
}
}
/// An environment is read-only access to variable values.

View file

@ -150,7 +150,7 @@ pub trait FloggableDisplay {
impl<T: std::fmt::Display> FloggableDisplay for T {
fn to_flog_str(&self) -> String {
format!("{}", self)
self.to_string()
}
}