From cce78eeb4339bcba704609e0ac8364d546d9c028 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 16 May 2023 20:11:05 -0500 Subject: [PATCH] Update env_var_to_ffi() to take an Option It wasn't possible to handle cases where vars.get() returned `None` then forward that to C++, but now we can. --- fish-rust/src/env/environment.rs | 8 ++++++-- fish-rust/src/flog.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fish-rust/src/env/environment.rs b/fish-rust/src/env/environment.rs index 0a0b30697..b92512984 100644 --- a/fish-rust/src/env/environment.rs +++ b/fish-rust/src/env/environment.rs @@ -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::new_ffi(Box::into_raw(Box::from(var)).cast()).within_unique_ptr() +pub fn env_var_to_ffi(var: Option) -> cxx::UniquePtr { + 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. diff --git a/fish-rust/src/flog.rs b/fish-rust/src/flog.rs index 9add0b6cd..56232c786 100644 --- a/fish-rust/src/flog.rs +++ b/fish-rust/src/flog.rs @@ -150,7 +150,7 @@ pub trait FloggableDisplay { impl FloggableDisplay for T { fn to_flog_str(&self) -> String { - format!("{}", self) + self.to_string() } }