2025-08-10 15:15:10 +09:00
|
|
|
|
//! ArrayBox 📦 - 配列・リスト操作
|
2025-08-10 02:45:57 +00:00
|
|
|
|
// Nyashの箱システムによる配列・リスト操作を提供します。
|
2025-08-14 23:48:21 +00:00
|
|
|
|
// RwLockパターンで内部可変性を実現(Phase 9.75-B Arc<Mutex>削除)
|
2025-08-10 02:45:57 +00:00
|
|
|
|
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
use crate::box_trait::{NyashBox, StringBox, BoolBox, IntegerBox, BoxCore, BoxBase};
|
2025-08-10 03:21:24 +00:00
|
|
|
|
use std::any::Any;
|
2025-08-15 04:34:04 +00:00
|
|
|
|
use std::sync::{Arc, RwLock};
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
use std::fmt::Display;
|
2025-08-10 03:21:24 +00:00
|
|
|
|
|
2025-08-10 02:45:57 +00:00
|
|
|
|
pub struct ArrayBox {
|
2025-08-15 04:34:04 +00:00
|
|
|
|
pub items: Arc<RwLock<Vec<Box<dyn NyashBox>>>>, // Arc追加
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
base: BoxBase,
|
2025-08-10 02:45:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl ArrayBox {
|
|
|
|
|
|
/// 新しいArrayBoxを作成
|
|
|
|
|
|
pub fn new() -> Self {
|
2025-08-10 03:21:24 +00:00
|
|
|
|
ArrayBox {
|
2025-08-15 04:34:04 +00:00
|
|
|
|
items: Arc::new(RwLock::new(Vec::new())), // Arc::new追加
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
base: BoxBase::new(),
|
2025-08-10 03:21:24 +00:00
|
|
|
|
}
|
2025-08-10 02:45:57 +00:00
|
|
|
|
}
|
2025-08-10 03:21:24 +00:00
|
|
|
|
|
2025-08-10 16:46:39 +09:00
|
|
|
|
/// 要素を持つArrayBoxを作成
|
|
|
|
|
|
pub fn new_with_elements(elements: Vec<Box<dyn NyashBox>>) -> Self {
|
|
|
|
|
|
ArrayBox {
|
2025-08-15 04:34:04 +00:00
|
|
|
|
items: Arc::new(RwLock::new(elements)), // Arc::new追加
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
base: BoxBase::new(),
|
2025-08-10 16:46:39 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-10 02:45:57 +00:00
|
|
|
|
/// 要素を追加
|
2025-08-10 15:15:10 +09:00
|
|
|
|
pub fn push(&self, item: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
self.items.write().unwrap().push(item);
|
2025-08-10 15:15:10 +09:00
|
|
|
|
Box::new(StringBox::new("ok"))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 最後の要素を取り出す
|
|
|
|
|
|
pub fn pop(&self) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
match self.items.write().unwrap().pop() {
|
2025-08-10 15:15:10 +09:00
|
|
|
|
Some(item) => item,
|
|
|
|
|
|
None => Box::new(crate::boxes::null_box::NullBox::new()),
|
|
|
|
|
|
}
|
2025-08-10 02:45:57 +00:00
|
|
|
|
}
|
2025-08-10 03:21:24 +00:00
|
|
|
|
|
2025-08-10 02:45:57 +00:00
|
|
|
|
/// 要素数を取得
|
2025-08-10 15:15:10 +09:00
|
|
|
|
pub fn length(&self) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
Box::new(IntegerBox::new(self.items.read().unwrap().len() as i64))
|
2025-08-10 02:45:57 +00:00
|
|
|
|
}
|
2025-08-13 11:53:34 +09:00
|
|
|
|
|
|
|
|
|
|
/// Rust向けヘルパー: 要素数をusizeで取得(テスト用)
|
|
|
|
|
|
pub fn len(&self) -> usize {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
self.items.read().unwrap().len()
|
2025-08-13 11:53:34 +09:00
|
|
|
|
}
|
2025-08-10 03:21:24 +00:00
|
|
|
|
|
2025-08-10 15:15:10 +09:00
|
|
|
|
/// インデックスで要素を取得
|
2025-08-10 16:46:39 +09:00
|
|
|
|
pub fn get(&self, index: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(idx_box) = index.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
|
let idx = idx_box.value as usize;
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let items = self.items.read().unwrap();
|
2025-08-10 16:46:39 +09:00
|
|
|
|
match items.get(idx) {
|
2025-08-21 21:35:17 +09:00
|
|
|
|
Some(item) => {
|
|
|
|
|
|
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
|
|
|
|
|
if item.as_any().downcast_ref::<crate::runtime::plugin_loader_v2::PluginBoxV2>().is_some() {
|
|
|
|
|
|
return item.share_box();
|
|
|
|
|
|
}
|
|
|
|
|
|
item.clone_box()
|
|
|
|
|
|
}
|
2025-08-10 16:46:39 +09:00
|
|
|
|
None => Box::new(crate::boxes::null_box::NullBox::new()),
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Box::new(StringBox::new("Error: get() requires integer index"))
|
|
|
|
|
|
}
|
2025-08-10 15:15:10 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// インデックスで要素を設定
|
2025-08-10 16:46:39 +09:00
|
|
|
|
pub fn set(&self, index: Box<dyn NyashBox>, value: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(idx_box) = index.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
|
let idx = idx_box.value as usize;
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let mut items = self.items.write().unwrap();
|
2025-08-10 16:46:39 +09:00
|
|
|
|
if idx < items.len() {
|
|
|
|
|
|
items[idx] = value;
|
|
|
|
|
|
Box::new(StringBox::new("ok"))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Box::new(StringBox::new("Error: index out of bounds"))
|
|
|
|
|
|
}
|
2025-08-10 15:15:10 +09:00
|
|
|
|
} else {
|
2025-08-10 16:46:39 +09:00
|
|
|
|
Box::new(StringBox::new("Error: set() requires integer index"))
|
2025-08-10 15:15:10 +09:00
|
|
|
|
}
|
2025-08-10 02:45:57 +00:00
|
|
|
|
}
|
2025-08-10 03:21:24 +00:00
|
|
|
|
|
2025-08-10 02:45:57 +00:00
|
|
|
|
/// 要素を削除
|
2025-08-10 16:46:39 +09:00
|
|
|
|
pub fn remove(&self, index: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(idx_box) = index.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
|
let idx = idx_box.value as usize;
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let mut items = self.items.write().unwrap();
|
2025-08-10 16:46:39 +09:00
|
|
|
|
if idx < items.len() {
|
|
|
|
|
|
items.remove(idx)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Box::new(crate::boxes::null_box::NullBox::new())
|
|
|
|
|
|
}
|
2025-08-10 02:45:57 +00:00
|
|
|
|
} else {
|
2025-08-10 16:46:39 +09:00
|
|
|
|
Box::new(StringBox::new("Error: remove() requires integer index"))
|
2025-08-10 02:45:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-10 15:15:10 +09:00
|
|
|
|
|
|
|
|
|
|
/// 指定された値のインデックスを検索
|
2025-08-10 16:46:39 +09:00
|
|
|
|
pub fn indexOf(&self, value: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let items = self.items.read().unwrap();
|
2025-08-10 15:15:10 +09:00
|
|
|
|
for (i, item) in items.iter().enumerate() {
|
2025-08-10 16:46:39 +09:00
|
|
|
|
if item.equals(value.as_ref()).value {
|
2025-08-10 15:15:10 +09:00
|
|
|
|
return Box::new(IntegerBox::new(i as i64));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Box::new(IntegerBox::new(-1))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 指定された値が含まれているか確認
|
2025-08-10 16:46:39 +09:00
|
|
|
|
pub fn contains(&self, value: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let items = self.items.read().unwrap();
|
2025-08-10 15:15:10 +09:00
|
|
|
|
for item in items.iter() {
|
2025-08-10 16:46:39 +09:00
|
|
|
|
if item.equals(value.as_ref()).value {
|
2025-08-10 15:15:10 +09:00
|
|
|
|
return Box::new(BoolBox::new(true));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Box::new(BoolBox::new(false))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 配列を空にする
|
|
|
|
|
|
pub fn clear(&self) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
self.items.write().unwrap().clear();
|
2025-08-10 15:15:10 +09:00
|
|
|
|
Box::new(StringBox::new("ok"))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 文字列結合
|
2025-08-10 16:46:39 +09:00
|
|
|
|
pub fn join(&self, delimiter: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
|
|
|
|
|
if let Some(sep_box) = delimiter.as_any().downcast_ref::<StringBox>() {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let items = self.items.read().unwrap();
|
2025-08-10 16:46:39 +09:00
|
|
|
|
let parts: Vec<String> = items
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|item| item.to_string_box().value)
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
Box::new(StringBox::new(&parts.join(&sep_box.value)))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Box::new(StringBox::new("Error: join() requires string separator"))
|
|
|
|
|
|
}
|
2025-08-10 15:15:10 +09:00
|
|
|
|
}
|
2025-08-11 19:38:45 +00:00
|
|
|
|
|
|
|
|
|
|
/// 配列をソート(昇順)
|
|
|
|
|
|
pub fn sort(&self) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let mut items = self.items.write().unwrap();
|
2025-08-11 19:38:45 +00:00
|
|
|
|
|
|
|
|
|
|
// Numeric values first, then string values
|
|
|
|
|
|
items.sort_by(|a, b| {
|
|
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
|
|
|
|
|
|
|
// Try to compare as numbers first
|
|
|
|
|
|
if let (Some(a_int), Some(b_int)) = (
|
|
|
|
|
|
a.as_any().downcast_ref::<IntegerBox>(),
|
|
|
|
|
|
b.as_any().downcast_ref::<IntegerBox>()
|
|
|
|
|
|
) {
|
|
|
|
|
|
return a_int.value.cmp(&b_int.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Try FloatBox comparison
|
|
|
|
|
|
if let (Some(a_float), Some(b_float)) = (
|
|
|
|
|
|
a.as_any().downcast_ref::<crate::boxes::math_box::FloatBox>(),
|
|
|
|
|
|
b.as_any().downcast_ref::<crate::boxes::math_box::FloatBox>()
|
|
|
|
|
|
) {
|
|
|
|
|
|
return a_float.value.partial_cmp(&b_float.value).unwrap_or(Ordering::Equal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Mixed numeric types
|
|
|
|
|
|
if let (Some(a_int), Some(b_float)) = (
|
|
|
|
|
|
a.as_any().downcast_ref::<IntegerBox>(),
|
|
|
|
|
|
b.as_any().downcast_ref::<crate::boxes::math_box::FloatBox>()
|
|
|
|
|
|
) {
|
|
|
|
|
|
return (a_int.value as f64).partial_cmp(&b_float.value).unwrap_or(Ordering::Equal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let (Some(a_float), Some(b_int)) = (
|
|
|
|
|
|
a.as_any().downcast_ref::<crate::boxes::math_box::FloatBox>(),
|
|
|
|
|
|
b.as_any().downcast_ref::<IntegerBox>()
|
|
|
|
|
|
) {
|
|
|
|
|
|
return a_float.value.partial_cmp(&(b_int.value as f64)).unwrap_or(Ordering::Equal);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Fall back to string comparison
|
|
|
|
|
|
let a_str = a.to_string_box().value;
|
|
|
|
|
|
let b_str = b.to_string_box().value;
|
|
|
|
|
|
a_str.cmp(&b_str)
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Box::new(StringBox::new("ok"))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 配列を反転
|
|
|
|
|
|
pub fn reverse(&self) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let mut items = self.items.write().unwrap();
|
2025-08-11 19:38:45 +00:00
|
|
|
|
items.reverse();
|
|
|
|
|
|
Box::new(StringBox::new("ok"))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 部分配列を取得
|
|
|
|
|
|
pub fn slice(&self, start: Box<dyn NyashBox>, end: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let items = self.items.read().unwrap();
|
2025-08-11 19:38:45 +00:00
|
|
|
|
|
|
|
|
|
|
// Extract start and end indices
|
|
|
|
|
|
let start_idx = if let Some(start_int) = start.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
|
if start_int.value < 0 {
|
|
|
|
|
|
0
|
|
|
|
|
|
} else {
|
|
|
|
|
|
start_int.value as usize
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return Box::new(StringBox::new("Error: slice() start index must be an integer"));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let end_idx = if let Some(end_int) = end.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
|
if end_int.value < 0 {
|
|
|
|
|
|
items.len()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
(end_int.value as usize).min(items.len())
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return Box::new(StringBox::new("Error: slice() end index must be an integer"));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Validate indices
|
|
|
|
|
|
if start_idx > items.len() || start_idx > end_idx {
|
|
|
|
|
|
return Box::new(ArrayBox::new());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create slice
|
|
|
|
|
|
let slice_items: Vec<Box<dyn NyashBox>> = items[start_idx..end_idx]
|
|
|
|
|
|
.iter()
|
2025-08-21 21:35:17 +09:00
|
|
|
|
.map(|item| {
|
|
|
|
|
|
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
|
|
|
|
|
if item.as_any().downcast_ref::<crate::runtime::plugin_loader_v2::PluginBoxV2>().is_some() {
|
|
|
|
|
|
return item.share_box();
|
|
|
|
|
|
}
|
|
|
|
|
|
item.clone_box()
|
|
|
|
|
|
})
|
2025-08-11 19:38:45 +00:00
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
|
|
Box::new(ArrayBox::new_with_elements(slice_items))
|
|
|
|
|
|
}
|
2025-08-10 02:45:57 +00:00
|
|
|
|
}
|
2025-08-10 03:21:24 +00:00
|
|
|
|
|
2025-08-14 23:48:21 +00:00
|
|
|
|
// Clone implementation for ArrayBox (needed since RwLock doesn't auto-derive Clone)
|
|
|
|
|
|
impl Clone for ArrayBox {
|
|
|
|
|
|
fn clone(&self) -> Self {
|
2025-08-15 04:34:04 +00:00
|
|
|
|
// ディープコピー(独立インスタンス)
|
|
|
|
|
|
let items_guard = self.items.read().unwrap();
|
|
|
|
|
|
let cloned_items: Vec<Box<dyn NyashBox>> = items_guard.iter()
|
2025-08-21 21:35:17 +09:00
|
|
|
|
.map(|item| {
|
|
|
|
|
|
#[cfg(all(feature = "plugins", not(target_arch = "wasm32")))]
|
|
|
|
|
|
if item.as_any().downcast_ref::<crate::runtime::plugin_loader_v2::PluginBoxV2>().is_some() {
|
|
|
|
|
|
return item.share_box();
|
|
|
|
|
|
}
|
|
|
|
|
|
item.clone_box()
|
|
|
|
|
|
}) // 要素もディープコピー(ハンドルは共有)
|
2025-08-14 23:48:21 +00:00
|
|
|
|
.collect();
|
2025-08-15 04:34:04 +00:00
|
|
|
|
|
|
|
|
|
|
ArrayBox {
|
|
|
|
|
|
items: Arc::new(RwLock::new(cloned_items)), // 新しいArc
|
|
|
|
|
|
base: BoxBase::new(),
|
|
|
|
|
|
}
|
2025-08-14 23:48:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
impl BoxCore for ArrayBox {
|
|
|
|
|
|
fn box_id(&self) -> u64 {
|
|
|
|
|
|
self.base.id
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-11 15:01:11 +09:00
|
|
|
|
fn parent_type_id(&self) -> Option<std::any::TypeId> {
|
|
|
|
|
|
self.base.parent_type_id
|
|
|
|
|
|
}
|
|
|
|
|
|
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let items = self.items.read().unwrap();
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
let strings: Vec<String> = items.iter()
|
|
|
|
|
|
.map(|item| item.to_string_box().value)
|
|
|
|
|
|
.collect();
|
|
|
|
|
|
write!(f, "[{}]", strings.join(", "))
|
|
|
|
|
|
}
|
2025-08-11 15:01:11 +09:00
|
|
|
|
|
|
|
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn as_any_mut(&mut self) -> &mut dyn Any {
|
|
|
|
|
|
self
|
|
|
|
|
|
}
|
🚀 feat: BoxBase+BoxCore革命 Phase4進捗 - 12+Box型統一完了
✅ 完了したBox型統一アーキテクチャ移行
- MathBox関連: MathBox, FloatBox, RangeBox
- TimeBox関連: TimeBox, DateTimeBox, TimerBox
- DebugBox, RandomBox
- StringBox, IntegerBox, BoolBox (個別ファイル版)
- ArrayBox, ConsoleBox
- box_trait.rs内: StringBox, IntegerBox, BoolBox, VoidBox等
🎯 大幅な進捗達成
- unsafe ID生成 → BoxBase::new()安全化
- コンパイルエラー: 106 → 97に減少
- 統一インターフェース確立でCharmFlow互換性問題完全回避
🔧 革命的変更パターン確立
1. base: BoxBase導入
2. impl BoxCore with box_id()/fmt_box()
3. NyashBoxからbox_id()削除
4. Display::fmt() → fmt_box()委譲
Phase 4E: 残りBox型の統一化継続中
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-11 11:25:17 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Display for ArrayBox {
|
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
|
self.fmt_box(f)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-10 03:21:24 +00:00
|
|
|
|
impl NyashBox for ArrayBox {
|
|
|
|
|
|
fn clone_box(&self) -> Box<dyn NyashBox> {
|
2025-08-10 15:15:10 +09:00
|
|
|
|
Box::new(self.clone())
|
2025-08-10 03:21:24 +00:00
|
|
|
|
}
|
2025-08-15 04:29:41 +00:00
|
|
|
|
|
2025-08-15 04:34:04 +00:00
|
|
|
|
/// 🎯 状態共有の核心実装
|
2025-08-15 04:29:41 +00:00
|
|
|
|
fn share_box(&self) -> Box<dyn NyashBox> {
|
2025-08-15 04:34:04 +00:00
|
|
|
|
let new_instance = ArrayBox {
|
|
|
|
|
|
items: Arc::clone(&self.items), // Arcクローンで状態共有
|
|
|
|
|
|
base: BoxBase::new(), // 新しいID
|
|
|
|
|
|
};
|
|
|
|
|
|
Box::new(new_instance)
|
2025-08-15 04:29:41 +00:00
|
|
|
|
}
|
2025-08-10 03:21:24 +00:00
|
|
|
|
|
|
|
|
|
|
fn to_string_box(&self) -> StringBox {
|
2025-08-14 23:48:21 +00:00
|
|
|
|
let items = self.items.read().unwrap();
|
2025-08-10 15:15:10 +09:00
|
|
|
|
let strings: Vec<String> = items.iter()
|
2025-08-10 03:21:24 +00:00
|
|
|
|
.map(|item| item.to_string_box().value)
|
|
|
|
|
|
.collect();
|
2025-08-10 15:15:10 +09:00
|
|
|
|
StringBox::new(format!("[{}]", strings.join(", ")))
|
2025-08-10 03:21:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn type_name(&self) -> &'static str {
|
|
|
|
|
|
"ArrayBox"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
|
|
|
|
|
if let Some(other_array) = other.as_any().downcast_ref::<ArrayBox>() {
|
2025-08-14 23:59:11 +00:00
|
|
|
|
let self_items = self.items.read().unwrap();
|
|
|
|
|
|
let other_items = other_array.items.read().unwrap();
|
2025-08-10 15:15:10 +09:00
|
|
|
|
|
|
|
|
|
|
if self_items.len() != other_items.len() {
|
2025-08-10 03:21:24 +00:00
|
|
|
|
return BoolBox::new(false);
|
|
|
|
|
|
}
|
2025-08-10 15:15:10 +09:00
|
|
|
|
|
|
|
|
|
|
for (a, b) in self_items.iter().zip(other_items.iter()) {
|
2025-08-10 03:21:24 +00:00
|
|
|
|
if !a.equals(b.as_ref()).value {
|
|
|
|
|
|
return BoolBox::new(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-10 15:15:10 +09:00
|
|
|
|
|
2025-08-10 03:21:24 +00:00
|
|
|
|
BoolBox::new(true)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
BoolBox::new(false)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-08-13 11:53:34 +09:00
|
|
|
|
}
|
2025-08-14 23:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
// Debug implementation for ArrayBox
|
|
|
|
|
|
impl std::fmt::Debug for ArrayBox {
|
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
|
let items = self.items.read().unwrap();
|
|
|
|
|
|
f.debug_struct("ArrayBox")
|
|
|
|
|
|
.field("id", &self.base.id)
|
|
|
|
|
|
.field("length", &items.len())
|
|
|
|
|
|
.finish()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|