mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 23:55:18 +02:00
Replace raw usize IDs with new types (#13832)
# Description In this PR I replaced most of the raw usize IDs with [newtypes](https://doc.rust-lang.org/rust-by-example/generics/new_types.html). Some other IDs already started using new types and in this PR I did not want to touch them. To make the implementation less repetitive, I made use of a generic `Id<T>` with marker structs. If this lands I would try to move make other IDs also in this pattern. Also at some places I needed to use `cast`, I'm not sure if the type was incorrect and therefore casting not needed or if actually different ID types intermingle sometimes. # User-Facing Changes Probably few, if you got a `DeclId` via a function and placed it later again it will still work.
This commit is contained in:
5
crates/nu-command/src/env/source_env.rs
vendored
5
crates/nu-command/src/env/source_env.rs
vendored
@ -2,7 +2,7 @@ use nu_engine::{
|
||||
command_prelude::*, find_in_dirs_env, get_dirs_var_from_call, get_eval_block_with_early_return,
|
||||
redirect_env,
|
||||
};
|
||||
use nu_protocol::engine::CommandType;
|
||||
use nu_protocol::{engine::CommandType, BlockId};
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Source a file for environment variables.
|
||||
@ -50,6 +50,7 @@ impl Command for SourceEnv {
|
||||
// Note: this hidden positional is the block_id that corresponded to the 0th position
|
||||
// it is put here by the parser
|
||||
let block_id: i64 = call.req_parser_info(engine_state, caller_stack, "block_id")?;
|
||||
let block_id = BlockId::new(block_id as usize);
|
||||
|
||||
// Set the currently evaluated directory (file-relative PWD)
|
||||
let file_path = if let Some(path) = find_in_dirs_env(
|
||||
@ -78,7 +79,7 @@ impl Command for SourceEnv {
|
||||
);
|
||||
|
||||
// Evaluate the block
|
||||
let block = engine_state.get_block(block_id as usize).clone();
|
||||
let block = engine_state.get_block(block_id).clone();
|
||||
let mut callee_stack = caller_stack
|
||||
.gather_captures(engine_state, &block.captures)
|
||||
.reset_pipes();
|
||||
|
Reference in New Issue
Block a user