🔧 refactor: すべてのBoxをArc<Mutex>パターンで統一

CopilotのBox実装を私たちのArc<Mutex>パターンで統一:
- BufferBox: Arc<Mutex<Vec<u8>>>で内部可変性を実現
- FileBox: Arc<Mutex<File>>でファイルハンドル管理
- JSONBox: Arc<Mutex<Value>>でJSON値を保持
- HttpClientBox: Arc<Mutex<Client>>でHTTPクライアント管理
- StreamBox: Arc<Mutex>でストリームバッファと位置を管理
- RegexBox: Arc<Regex>で軽量ラッパー実装

各Boxに実用的なメソッドも追加:
- BufferBox: write, read, readAll, clear, length, append, slice
- FileBox: read, write, exists, delete, copy
- JSONBox: parse, stringify, get, set, has, keys
- HttpClientBox: get, post, put, delete, request
- StreamBox: write, read, position, length, reset
- RegexBox: test, find, findAll, replace, split

interpreterに新Box用のメソッド実行を追加:
- data_methods.rs: BufferBox, JSONBox, RegexBox
- network_methods.rs: HttpClientBox, StreamBox

これでコードベース全体が一貫性のある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 13:03:42 +09:00
parent b745f5ffa2
commit 750543be7c
12 changed files with 989 additions and 110 deletions

View File

@ -80,23 +80,28 @@ impl NyashBox for NyashResultBox {
}
}
// Keep the original generic ResultBox for compatibility
pub enum ResultBox<T, E> {
Ok(T),
Err(E),
}
// Export NyashResultBox as ResultBox for compatibility
pub type ResultBox = NyashResultBox;
impl<T, E> ResultBox<T, E> {
pub fn is_ok(&self) -> bool {
matches!(self, ResultBox::Ok(_))
impl ResultBox {
/// is_ok()の実装
pub fn is_ok(&self) -> Box<dyn NyashBox> {
Box::new(BoolBox::new(matches!(self, NyashResultBox::Ok(_))))
}
pub fn is_err(&self) -> bool {
matches!(self, ResultBox::Err(_))
}
pub fn unwrap(self) -> T {
/// getValue()の実装 - Ok値を取得
pub fn get_value(&self) -> Box<dyn NyashBox> {
match self {
ResultBox::Ok(val) => val,
ResultBox::Err(_) => panic!("called `unwrap()` on an `Err` value"),
NyashResultBox::Ok(val) => val.clone_box(),
NyashResultBox::Err(_) => Box::new(StringBox::new("Error: Result is Err")),
}
}
/// getError()の実装 - Err値を取得
pub fn get_error(&self) -> Box<dyn NyashBox> {
match self {
NyashResultBox::Ok(_) => Box::new(StringBox::new("Error: Result is Ok")),
NyashResultBox::Err(err) => err.clone_box(),
}
}
}