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")?;