🔥 feat: Arc<Mutex> Revolution完全達成 - 全Box型統一実装

## 🎯 主要な変更
- ArrayBoxをArc<Mutex>パターンで完全再実装
- 全メソッドが`&self`で統一(push, pop, get, set等)
- Box<dyn NyashBox>引数対応でNyashから使用可能に

##  修正内容
- ArrayBox: 完全なArc<Mutex>実装に置き換え
- BufferBox: ArrayBoxとの連携修正、デバッグ出力削除
- StringBox: 新しいArrayBoxインポートに修正
- RandomBox: 新しいArrayBoxインポートに修正
- box_trait.rs: 古いArrayBox定義を削除しre-export追加

## 🧪 テスト追加
- test_buffer_box.nyash: BufferBox動作確認
- test_random_box.nyash: RandomBox動作確認
- test_new_boxes.nyash: 包括的Box機能テスト修正

##  確認済み動作
- ArrayBox: push/pop/get/set/join等全メソッド
- BufferBox: write/readAll/length
- RandomBox: choice/shuffle等配列操作
- JSONBox/RegexBox: 既に正しく実装済み

🚀 全Box型がArc<Mutex>パターンで統一完了!

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-10 16:46:39 +09:00
parent dff165db8d
commit 0c786a8ac6
8 changed files with 146 additions and 182 deletions

View File

@ -67,7 +67,8 @@
* - 大きな配列のshuffleは処理時間が長い場合あり
*/
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox, ArrayBox};
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox};
use crate::boxes::array::ArrayBox;
use crate::boxes::math_box::FloatBox;
use std::fmt::{Debug, Display};
use std::any::Any;
@ -159,10 +160,8 @@ impl RandomBox {
}
let index = self.next_random() % (length as u64);
match array_box.get(index as usize) {
Some(element) => element,
None => Box::new(StringBox::new("Error: index out of bounds")),
}
// 新しいArrayBox.get()は既にBox<dyn NyashBox>を返すので、直接使用
array_box.get(Box::new(IntegerBox::new(index as i64)))
} else {
Box::new(StringBox::new("Error: choice() requires array input"))
}
@ -181,7 +180,9 @@ impl RandomBox {
// 元の配列の要素を全て新しい配列にコピー
for i in 0..length {
if let Some(element) = array_box.get(i as usize) {
let element = array_box.get(Box::new(IntegerBox::new(i as i64)));
// NullBoxでなければ追加
if element.type_name() != "NullBox" {
shuffled.push(element);
}
}
@ -194,7 +195,9 @@ impl RandomBox {
while !remaining_indices.is_empty() {
let random_idx = (self.next_random() % remaining_indices.len() as u64) as usize;
let actual_idx = remaining_indices.remove(random_idx);
if let Some(element) = array_box.get(actual_idx) {
let element = array_box.get(Box::new(IntegerBox::new(actual_idx as i64)));
// NullBoxでなければ追加
if element.type_name() != "NullBox" {
result.push(element);
}
}