mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 12:58:11 +02:00
Make get_env_var
return a reference to a Value
(#13987)
# Description Title says it all, changes `EngineState::get_env_var` to return a `Option<&'a Value>` instead of an owned `Option<Value>`. This avoids some unnecessary clones. I also made a similar change to the `PluginExecutionContext` trait.
This commit is contained in:
@ -25,7 +25,7 @@ pub trait PluginExecutionContext: Send + Sync {
|
||||
/// Get plugin configuration
|
||||
fn get_plugin_config(&self) -> Result<Option<Value>, ShellError>;
|
||||
/// Get an environment variable from `$env`
|
||||
fn get_env_var(&self, name: &str) -> Result<Option<Value>, ShellError>;
|
||||
fn get_env_var(&self, name: &str) -> Result<Option<&Value>, ShellError>;
|
||||
/// Get all environment variables
|
||||
fn get_env_vars(&self) -> Result<HashMap<String, Value>, ShellError>;
|
||||
/// Get current working directory
|
||||
@ -125,7 +125,7 @@ impl<'a> PluginExecutionContext for PluginExecutionCommandContext<'a> {
|
||||
}))
|
||||
}
|
||||
|
||||
fn get_env_var(&self, name: &str) -> Result<Option<Value>, ShellError> {
|
||||
fn get_env_var(&self, name: &str) -> Result<Option<&Value>, ShellError> {
|
||||
Ok(self.stack.get_env_var(&self.engine_state, name))
|
||||
}
|
||||
|
||||
@ -300,7 +300,7 @@ impl PluginExecutionContext for PluginExecutionBogusContext {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn get_env_var(&self, _name: &str) -> Result<Option<Value>, ShellError> {
|
||||
fn get_env_var(&self, _name: &str) -> Result<Option<&Value>, ShellError> {
|
||||
Err(ShellError::NushellFailed {
|
||||
msg: "get_env_var not implemented on bogus".into(),
|
||||
})
|
||||
|
Reference in New Issue
Block a user