🎉 feat: BoxBase+BoxCore革命 Phase4F-G完了 - GUI/IO/データ系Box統一達成

 新たに完了したBox型統一アーキテクチャ移行
- EguiBox: GUI機能、デスクトップアプリケーション対応 🖼️
- BufferBox: バイナリデータ処理、メモリ効率最適化 📦
- FileBox: ファイルシステム操作、安全なIO処理 📁
- JSONBox: JSON解析/操作、型情報豊富な表示 📋

🎯 累積達成: 20+Box型の統一アーキテクチャ移行完了
- 音声系: SoundBox 
- データ系: MapBox, BufferBox, JSONBox 
- UI系: EguiBox 
- IO系: FileBox 
- 数学系: MathBox, FloatBox, RangeBox 
- 時間系: TimeBox, DateTimeBox, TimerBox 
- デバッグ系: DebugBox, RandomBox 
- 基本型: String/Integer/Bool等 

🔧 統一パターン確立による効果
- unsafe ID生成完全排除 → BoxBase::new()安全化
- 一貫したfmt_box()表示システム
- CharmFlow互換性問題の根本解決
- スレッドセーフ性とメモリ安全性向上

🐱 ゆっくり丁寧なアプローチで品質確保
Phase4継続中: 残り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:45:34 +09:00
parent edcf4bf0a7
commit 8892b0c006
6 changed files with 125 additions and 78 deletions

View File

@ -28,7 +28,7 @@
* ```
*/
use crate::box_trait::{NyashBox, StringBox, BoolBox, IntegerBox};
use crate::box_trait::{NyashBox, StringBox, BoolBox, IntegerBox, BoxCore, BoxBase};
use crate::boxes::array::ArrayBox;
use std::any::Any;
use std::sync::{Arc, Mutex};
@ -37,31 +37,21 @@ use std::fmt::{Debug, Display};
#[derive(Debug, Clone)]
pub struct BufferBox {
data: Arc<Mutex<Vec<u8>>>,
id: u64,
base: BoxBase,
}
impl BufferBox {
pub fn new() -> Self {
static mut COUNTER: u64 = 0;
let id = unsafe {
COUNTER += 1;
COUNTER
};
BufferBox {
data: Arc::new(Mutex::new(Vec::new())),
id,
base: BoxBase::new(),
}
}
pub fn from_vec(data: Vec<u8>) -> Self {
static mut COUNTER: u64 = 0;
let id = unsafe {
COUNTER += 1;
COUNTER
};
BufferBox {
data: Arc::new(Mutex::new(data)),
id,
base: BoxBase::new(),
}
}
@ -158,6 +148,23 @@ impl BufferBox {
}
}
impl BoxCore for BufferBox {
fn box_id(&self) -> u64 {
self.base.id
}
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let data = self.data.lock().unwrap();
write!(f, "BufferBox({} bytes)", data.len())
}
}
impl Display for BufferBox {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.fmt_box(f)
}
}
impl NyashBox for BufferBox {
fn clone_box(&self) -> Box<dyn NyashBox> {
Box::new(self.clone())
@ -176,9 +183,6 @@ impl NyashBox for BufferBox {
"BufferBox"
}
fn box_id(&self) -> u64 {
self.id
}
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
if let Some(other_buffer) = other.as_any().downcast_ref::<BufferBox>() {