mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 14:50:02 +02:00
# Description see https://github.com/nushell/nushell/issues/9390 using `ahash` instead of the default hasher. this will not affect compile time as we where already building `ahash`. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
74 lines
1.9 KiB
Rust
74 lines
1.9 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{span, ModuleId, Span};
|
|
use ahash::{HashSet, HashSetExt};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum ImportPatternMember {
|
|
Glob { span: Span },
|
|
Name { name: Vec<u8>, span: Span },
|
|
List { names: Vec<(Vec<u8>, Span)> },
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct ImportPatternHead {
|
|
pub name: Vec<u8>,
|
|
pub id: Option<ModuleId>,
|
|
pub span: Span,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct ImportPattern {
|
|
pub head: ImportPatternHead,
|
|
pub members: Vec<ImportPatternMember>,
|
|
// communicate to eval which decls/aliases were hidden during `parse_hide()` so it does not
|
|
// interpret these as env var names:
|
|
pub hidden: HashSet<Vec<u8>>,
|
|
}
|
|
|
|
impl ImportPattern {
|
|
pub fn new() -> Self {
|
|
ImportPattern {
|
|
head: ImportPatternHead {
|
|
name: vec![],
|
|
id: None,
|
|
span: Span::unknown(),
|
|
},
|
|
members: vec![],
|
|
hidden: HashSet::new(),
|
|
}
|
|
}
|
|
|
|
pub fn span(&self) -> Span {
|
|
let mut spans = vec![self.head.span];
|
|
|
|
for member in &self.members {
|
|
match member {
|
|
ImportPatternMember::Glob { span } => spans.push(*span),
|
|
ImportPatternMember::Name { name: _, span } => spans.push(*span),
|
|
ImportPatternMember::List { names } => {
|
|
for (_, span) in names {
|
|
spans.push(*span);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
span(&spans)
|
|
}
|
|
|
|
pub fn with_hidden(self, hidden: HashSet<Vec<u8>>) -> Self {
|
|
ImportPattern {
|
|
head: self.head,
|
|
members: self.members,
|
|
hidden,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for ImportPattern {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|