🎉 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:
@ -2,7 +2,7 @@
|
||||
// Nyashの箱システムによるファイル入出力を提供します。
|
||||
// 参考: 既存Boxの設計思想
|
||||
|
||||
use crate::box_trait::{NyashBox, StringBox, BoolBox};
|
||||
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
|
||||
use std::any::Any;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write, Result};
|
||||
@ -12,21 +12,16 @@ use std::sync::{Arc, Mutex};
|
||||
pub struct FileBox {
|
||||
file: Arc<Mutex<File>>,
|
||||
path: Arc<String>,
|
||||
id: u64,
|
||||
base: BoxBase,
|
||||
}
|
||||
|
||||
impl FileBox {
|
||||
pub fn open(path: &str) -> Result<Self> {
|
||||
static mut COUNTER: u64 = 0;
|
||||
let id = unsafe {
|
||||
COUNTER += 1;
|
||||
COUNTER
|
||||
};
|
||||
let file = OpenOptions::new().read(true).write(true).create(true).open(path)?;
|
||||
Ok(FileBox {
|
||||
file: Arc::new(Mutex::new(file)),
|
||||
path: Arc::new(path.to_string()),
|
||||
id,
|
||||
base: BoxBase::new(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -82,6 +77,16 @@ impl FileBox {
|
||||
}
|
||||
}
|
||||
|
||||
impl BoxCore for FileBox {
|
||||
fn box_id(&self) -> u64 {
|
||||
self.base.id
|
||||
}
|
||||
|
||||
fn fmt_box(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "FileBox({})", self.path)
|
||||
}
|
||||
}
|
||||
|
||||
impl NyashBox for FileBox {
|
||||
fn clone_box(&self) -> Box<dyn NyashBox> {
|
||||
// Note: Cannot truly clone a File handle, so create a new one to the same path
|
||||
@ -103,9 +108,6 @@ impl NyashBox for FileBox {
|
||||
"FileBox"
|
||||
}
|
||||
|
||||
fn box_id(&self) -> u64 {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||||
if let Some(other_file) = other.as_any().downcast_ref::<FileBox>() {
|
||||
@ -115,3 +117,9 @@ impl NyashBox for FileBox {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for FileBox {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.fmt_box(f)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user