Expose env_dyn_t in env.h

So that we may use it from files other than `src/env.cpp` to accept a
`&dyn Environment` out of rust.
This commit is contained in:
Mahmoud Al-Qudsi 2023-05-16 18:02:18 -05:00
parent 6bb2725f67
commit 32912b6525
2 changed files with 25 additions and 19 deletions

View File

@ -450,27 +450,18 @@ std::shared_ptr<owning_null_terminated_array_t> env_stack_t::export_arr() {
rust::Box<OwningNullTerminatedArrayRefFFI>::from_raw(ptr));
}
/// Wrapper around a EnvDyn.
class env_dyn_t final : public environment_t {
public:
env_dyn_t(rust::Box<EnvDyn> impl) : impl_(std::move(impl)) {}
maybe_t<env_var_t> get(const wcstring &key, env_mode_flags_t mode) const {
if (auto *ptr = impl_->getf(key, mode)) {
return env_var_t::new_ffi(ptr);
}
return none();
maybe_t<env_var_t> env_dyn_t::get(const wcstring &key, env_mode_flags_t mode) const {
if (auto *ptr = impl_->getf(key, mode)) {
return env_var_t::new_ffi(ptr);
}
return none();
}
std::vector<wcstring> get_names(env_mode_flags_t flags) const {
wcstring_list_ffi_t names;
impl_->get_names(flags, names);
return std::move(names.vals);
}
private:
rust::Box<EnvDyn> impl_;
};
std::vector<wcstring> env_dyn_t::get_names(env_mode_flags_t flags) const {
wcstring_list_ffi_t names;
impl_->get_names(flags, names);
return std::move(names.vals);
}
std::shared_ptr<environment_t> env_stack_t::snapshot() const {
auto res = std::make_shared<env_dyn_t>(impl_->snapshot());

View File

@ -313,6 +313,21 @@ bool get_use_posix_spawn();
/// Returns true if we think the terminal supports setting its title.
bool term_supports_setting_title();
#if INCLUDE_RUST_HEADERS
struct EnvDyn;
/// Wrapper around rust's `&dyn Environment` deriving from `environment_t`.
class env_dyn_t final : public environment_t {
public:
env_dyn_t(rust::Box<EnvDyn> impl) : impl_(std::move(impl)) {}
maybe_t<env_var_t> get(const wcstring &key, env_mode_flags_t mode) const;
std::vector<wcstring> get_names(env_mode_flags_t flags) const;
private:
rust::Box<EnvDyn> impl_;
};
#endif
/// Gets a path appropriate for runtime storage
wcstring env_get_runtime_path();