🚀 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>
This commit is contained in:
Moe Charm
2025-08-11 11:25:17 +09:00
parent 73a12dfb56
commit edcf4bf0a7
11 changed files with 260 additions and 1512 deletions

View File

@ -67,7 +67,7 @@
* - 大きな配列のshuffleは処理時間が長い場合あり
*/
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox};
use crate::box_trait::{NyashBox, StringBox, IntegerBox, BoolBox, BoxCore, BoxBase};
use crate::boxes::array::ArrayBox;
use crate::boxes::math_box::FloatBox;
use std::fmt::{Debug, Display};
@ -79,17 +79,11 @@ use std::sync::{Arc, Mutex};
pub struct RandomBox {
// 簡易線形合同法による疑似乱数生成器
seed: Arc<Mutex<u64>>,
id: u64,
base: BoxBase,
}
impl RandomBox {
pub fn new() -> Self {
static mut COUNTER: u64 = 0;
let id = unsafe {
COUNTER += 1;
COUNTER
};
// 現在時刻を種として使用
let seed = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
@ -98,7 +92,7 @@ impl RandomBox {
Self {
seed: Arc::new(Mutex::new(seed)),
id,
base: BoxBase::new(),
}
}
@ -268,7 +262,7 @@ impl NyashBox for RandomBox {
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
if let Some(other_random) = other.as_any().downcast_ref::<RandomBox>() {
BoolBox::new(self.id == other_random.id)
BoolBox::new(self.base.id == other_random.base.id)
} else {
BoolBox::new(false)
}
@ -278,13 +272,20 @@ impl NyashBox for RandomBox {
self
}
}
impl BoxCore for RandomBox {
fn box_id(&self) -> u64 {
self.id
self.base.id
}
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "RandomBox()")
}
}
impl Display for RandomBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "RandomBox()")
self.fmt_box(f)
}
}