Skip to main content

NameTable

Struct NameTable 

Source
pub struct NameTable { /* private fields */ }
Expand description

名字表:单元级「名字 ↔ u32」intern(只增、永不回收)+ 每节点的 名字键(槽位 = arena 下标,KEY_NONE = 无名)。

语言的 Lang::NameKey 采用 intern u32 时(推荐——区域扫描的名字 比较退化为整数等值)直接复用本表。

Implementations§

Source§

impl NameTable

Source

pub fn new() -> Self

Source

pub fn intern(&mut self, name: &str) -> u32

名字 → 键(intern:同名字同键)。

Source

pub fn name(&self, key: u32) -> &str

键 → 名字原文(未知键返回空串,与调用方 sn 惯例一致)。

Source

pub fn var_key(&self, idx: usize) -> Option<u32>

节点名字键(KEY_NONE → None;供 Lang::var_key)。

Source

pub fn raw_key(&self, idx: usize) -> u32

原始键(含 KEY_NONE;供兼容旧路径)。

Source

pub fn key_slots(&self) -> usize

已填充的节点键槽数(与 arena 下标对齐检查用)。

Source

pub fn extend_owned(&mut self, base: usize, names: &[Option<String>])

增量扩展节点键表:为下标 [base, base + names.len()) 的新 节点填键(名字已由语言侧先收集——Lang::var_name 的借用安全 形态)。既有节点的键与其名字恒同,无需重填。

Trait Implementations§

Source§

impl Debug for NameTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NameTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.