mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
24 lines
566 B
Rust
24 lines
566 B
Rust
use ruff_python_ast::{AnyNodeRef, NodeKind};
|
|
use ruff_text_size::{Ranged, TextRange};
|
|
|
|
/// Compact key for a node for use in a hash map.
|
|
///
|
|
/// Compares two nodes by their kind and text range.
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
pub(super) struct NodeKey {
|
|
kind: NodeKind,
|
|
range: TextRange,
|
|
}
|
|
|
|
impl NodeKey {
|
|
pub(super) fn from_node<'a, N>(node: N) -> Self
|
|
where
|
|
N: Into<AnyNodeRef<'a>>,
|
|
{
|
|
let node = node.into();
|
|
NodeKey {
|
|
kind: node.kind(),
|
|
range: node.range(),
|
|
}
|
|
}
|
|
}
|