Add core Box implementations: ArrayBox, ResultBox, FutureBox, BufferBox, FileBox, JSONBox, HttpClientBox, StreamBox, RegexBox

This commit is contained in:
moe-charm
2025-08-10 02:45:57 +00:00
parent ccb3204a35
commit 6f916855c8
9 changed files with 207 additions and 0 deletions

25
src/boxes/file/mod.rs Normal file
View File

@ -0,0 +1,25 @@
//! FileBox 📁 - ファイルI/OPathBox/DirBoxとセット
// Nyashの箱システムによるファイル入出力を提供します。
// 参考: 既存Boxの設計思想
use std::fs::{File, OpenOptions};
use std::io::{Read, Write, Result};
pub struct FileBox {
pub file: File,
}
impl FileBox {
pub fn open(path: &str) -> Result<Self> {
let file = OpenOptions::new().read(true).write(true).create(true).open(path)?;
Ok(FileBox { file })
}
pub fn read_to_string(&mut self) -> Result<String> {
let mut s = String::new();
self.file.read_to_string(&mut s)?;
Ok(s)
}
pub fn write_all(&mut self, buf: &[u8]) -> Result<()> {
self.file.write_all(buf)
}
}