sightline-ty-python-core 0.1.0

sightline's fork of ty_python_core, an internal crate of ruff and ty (astral-sh/ruff), as the sightline binary pins it
Documentation
use ruff_python_ast::{HasNodeIndex, NodeIndex};

use crate::ast_node_ref::AstNodeRef;

/// Compact key for a node for use in a hash map.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, get_size2::GetSize)]
pub struct NodeKey(NodeIndex);

impl NodeKey {
    /// Returns the index of the AST node.
    pub fn index(self) -> NodeIndex {
        self.0
    }

    pub fn from_node<N>(node: N) -> Self
    where
        N: HasNodeIndex,
    {
        NodeKey(node.node_index().load())
    }

    pub fn from_node_ref<T>(node_ref: &AstNodeRef<T>) -> Self {
        NodeKey(node_ref.index())
    }
}