From 8995fd151df12cc38a99da0e124fd2cb2f7a3ac5 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Wed, 3 Dec 2025 10:30:26 +0900 Subject: [PATCH] =?UTF-8?q?refactor(phase96.5):=20use=E6=96=87=E6=95=B4?= =?UTF-8?q?=E7=90=86=E3=81=A8=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20-=20=E3=82=B3=E3=83=BC=E3=83=89=E5=8F=AF=E8=AA=AD?= =?UTF-8?q?=E6=80=A7=E5=90=91=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> { 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> { // 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 --- src/runtime/core_services.rs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/runtime/core_services.rs b/src/runtime/core_services.rs index 278154e9..356cb17c 100644 --- a/src/runtime/core_services.rs +++ b/src/runtime/core_services.rs @@ -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, @@ -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, @@ -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::() .map(|a| a.len() as i64) @@ -209,16 +213,12 @@ impl ArrayService for ArrayBoxAdapter { } fn get(&self, arr: &dyn NyashBox, index: i64) -> Option> { - use crate::boxes::array::ArrayBox; - use crate::box_trait::IntegerBox; let arr_box = arr.as_any().downcast_ref::()?; let index_box = Box::new(IntegerBox::new(index)); Some(arr_box.get(index_box)) } fn set(&self, arr: &dyn NyashBox, index: i64, value: Box) -> Result<(), String> { - use crate::boxes::array::ArrayBox; - use crate::box_trait::IntegerBox; let arr_box = arr.as_any() .downcast_ref::() .ok_or("Not an ArrayBox")?; @@ -228,7 +228,6 @@ impl ArrayService for ArrayBoxAdapter { } fn push(&self, arr: &dyn NyashBox, value: Box) -> Result<(), String> { - use crate::boxes::array::ArrayBox; let arr_box = arr.as_any() .downcast_ref::() .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::() .map(|m| { // MapBox::size() は Box を返すため、IntegerBox に変換 let size_box = m.size(); size_box.as_any() - .downcast_ref::() + .downcast_ref::() .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::() { Some(m) => m, None => return false, @@ -280,16 +276,12 @@ impl MapService for MapBoxAdapter { } fn get(&self, map: &dyn NyashBox, key: &str) -> Option> { - use crate::boxes::map_box::MapBox; - use crate::box_trait::StringBox; let map_box = map.as_any().downcast_ref::()?; let key_box = Box::new(StringBox::new(key)); Some(map_box.get(key_box)) } fn set(&self, map: &dyn NyashBox, key: &str, value: Box) -> Result<(), String> { - use crate::boxes::map_box::MapBox; - use crate::box_trait::StringBox; let map_box = map.as_any() .downcast_ref::() .ok_or("Not a MapBox")?;