refactor(phase96.5): use文整理とコメント更新 - コード可読性向上

Phase 96.5完了 - コード整理とメンテナンス性向上

### 変更内容
-  use文をトップレベルに集約(10行削除)
-  コメント更新(Phase 96 → Phase 97)
-  テスト9/9 PASS(100%)

### use文整理
**Before**: 各メソッド内で重複import
```rust
fn get(&self, arr: &dyn NyashBox, index: i64) -> Option<Box<dyn NyashBox>> {
    use crate::boxes::array::ArrayBox;  // 重複
    use crate::box_trait::IntegerBox;   // 重複
    // ...
}
```

**After**: トップレベルで一度だけimport
```rust
// トップレベル
use crate::boxes::array::ArrayBox;
use crate::boxes::map_box::MapBox;
use crate::box_trait::{IntegerBox, StringBox, BoolBox};

fn get(&self, arr: &dyn NyashBox, index: i64) -> Option<Box<dyn NyashBox>> {
    // use不要!スッキリ!
}
```

### コメント更新
- IntegerBoxAdapter: "Phase 96 以降で実装" → "Phase 97 で実装予定(純粋関数型として実装)"
- BoolBoxAdapter: "Phase 96 以降で実装" → "Phase 97 で実装予定(純粋関数型として実装)"

### 改善効果
-  可読性向上(use文の重複削除)
-  メンテナンス性向上(import一箇所集約)
-  コメント整合性(実際のPhase計画と一致)

### 削減統計
- use文: 10行削除
- コメント: 2箇所更新

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-03 10:30:26 +09:00
parent 81a5a04eb7
commit 8995fd151d

View File

@ -7,6 +7,11 @@ use std::sync::Arc;
use crate::runtime::CoreBoxId;
use crate::box_trait::NyashBox;
// Phase 96.5: Adapter実装で使用するBox型をトップレベルでimport
use crate::boxes::array::ArrayBox;
use crate::boxes::map_box::MapBox;
use crate::box_trait::{IntegerBox, StringBox, BoolBox};
/// StringBox Service trait
///
/// Phase 95: len のみ実装
@ -153,7 +158,7 @@ impl StringService for StringBoxAdapter {
/// IntegerBox → IntegerService Adapter
///
/// Phase 95.5: inner フィールドは #[allow(dead_code)] のまま保持
/// Phase 96 以降で実装時に、Box 状態が必要か純粋関数で足りるか判断
/// Phase 97 で実装予定(純粋関数型として実装)
pub struct IntegerBoxAdapter {
#[allow(dead_code)]
inner: Box<dyn NyashBox>,
@ -166,13 +171,13 @@ impl IntegerBoxAdapter {
}
impl IntegerService for IntegerBoxAdapter {
// Phase 96 以降で実装
// Phase 97 で実装予定
}
/// BoolBox → BoolService Adapter
///
/// Phase 95.5: inner フィールドは #[allow(dead_code)] のまま保持
/// Phase 96 以降で実装時に、Box 状態が必要か純粋関数で足りるか判断
/// Phase 97 で実装予定(純粋関数型として実装)
pub struct BoolBoxAdapter {
#[allow(dead_code)]
inner: Box<dyn NyashBox>,
@ -185,7 +190,7 @@ impl BoolBoxAdapter {
}
impl BoolService for BoolBoxAdapter {
// Phase 96 以降で実装
// Phase 97 で実装予定
}
/// ArrayBox → ArrayService Adapter
@ -201,7 +206,6 @@ impl ArrayBoxAdapter {
impl ArrayService for ArrayBoxAdapter {
fn len(&self, arr: &dyn NyashBox) -> i64 {
use crate::boxes::array::ArrayBox;
arr.as_any()
.downcast_ref::<ArrayBox>()
.map(|a| a.len() as i64)
@ -209,16 +213,12 @@ impl ArrayService for ArrayBoxAdapter {
}
fn get(&self, arr: &dyn NyashBox, index: i64) -> Option<Box<dyn NyashBox>> {
use crate::boxes::array::ArrayBox;
use crate::box_trait::IntegerBox;
let arr_box = arr.as_any().downcast_ref::<ArrayBox>()?;
let index_box = Box::new(IntegerBox::new(index));
Some(arr_box.get(index_box))
}
fn set(&self, arr: &dyn NyashBox, index: i64, value: Box<dyn NyashBox>) -> Result<(), String> {
use crate::boxes::array::ArrayBox;
use crate::box_trait::IntegerBox;
let arr_box = arr.as_any()
.downcast_ref::<ArrayBox>()
.ok_or("Not an ArrayBox")?;
@ -228,7 +228,6 @@ impl ArrayService for ArrayBoxAdapter {
}
fn push(&self, arr: &dyn NyashBox, value: Box<dyn NyashBox>) -> Result<(), String> {
use crate::boxes::array::ArrayBox;
let arr_box = arr.as_any()
.downcast_ref::<ArrayBox>()
.ok_or("Not an ArrayBox")?;
@ -250,14 +249,13 @@ impl MapBoxAdapter {
impl MapService for MapBoxAdapter {
fn size(&self, map: &dyn NyashBox) -> i64 {
use crate::boxes::map_box::MapBox;
map.as_any()
.downcast_ref::<MapBox>()
.map(|m| {
// MapBox::size() は Box<dyn NyashBox> を返すため、IntegerBox に変換
let size_box = m.size();
size_box.as_any()
.downcast_ref::<crate::box_trait::IntegerBox>()
.downcast_ref::<IntegerBox>()
.map(|i| i.value)
.unwrap_or(0)
})
@ -265,8 +263,6 @@ impl MapService for MapBoxAdapter {
}
fn has(&self, map: &dyn NyashBox, key: &str) -> bool {
use crate::boxes::map_box::MapBox;
use crate::box_trait::{BoolBox, StringBox};
let map_box = match map.as_any().downcast_ref::<MapBox>() {
Some(m) => m,
None => return false,
@ -280,16 +276,12 @@ impl MapService for MapBoxAdapter {
}
fn get(&self, map: &dyn NyashBox, key: &str) -> Option<Box<dyn NyashBox>> {
use crate::boxes::map_box::MapBox;
use crate::box_trait::StringBox;
let map_box = map.as_any().downcast_ref::<MapBox>()?;
let key_box = Box::new(StringBox::new(key));
Some(map_box.get(key_box))
}
fn set(&self, map: &dyn NyashBox, key: &str, value: Box<dyn NyashBox>) -> Result<(), String> {
use crate::boxes::map_box::MapBox;
use crate::box_trait::StringBox;
let map_box = map.as_any()
.downcast_ref::<MapBox>()
.ok_or("Not a MapBox")?;