chore(fmt): add legacy stubs and strip trailing whitespace to unblock cargo fmt
This commit is contained in:
@ -1,29 +1,29 @@
|
||||
/*! 📦 IntentBox - Structured Message Box
|
||||
*
|
||||
*
|
||||
* ## 📝 概要
|
||||
* IntentBoxは構造化メッセージを表現するBoxです。
|
||||
* P2P通信において、メッセージの種類(name)と内容(payload)を
|
||||
* 明確に分離して管理します。
|
||||
*
|
||||
*
|
||||
* ## 🏗️ 設計
|
||||
* - **name**: メッセージの種類 ("chat.message", "file.share"等)
|
||||
* - **payload**: JSON形式の任意データ
|
||||
* - **Arc<Mutex>**: 他のBoxと統一されたメモリ管理パターン
|
||||
*
|
||||
*
|
||||
* ## 🛠️ 利用可能メソッド
|
||||
* - `new(name, payload)` - 構造化メッセージを作成
|
||||
* - `getName()` - メッセージ名を取得
|
||||
* - `getPayload()` - ペイロードを取得
|
||||
* - `setPayload(data)` - ペイロードを更新
|
||||
*
|
||||
*
|
||||
* ## 💡 使用例
|
||||
* ```nyash
|
||||
* // チャットメッセージ
|
||||
* local msg = new IntentBox("chat.message", {
|
||||
* text: "Hello P2P!",
|
||||
* from: "alice"
|
||||
* local msg = new IntentBox("chat.message", {
|
||||
* text: "Hello P2P!",
|
||||
* from: "alice"
|
||||
* })
|
||||
*
|
||||
*
|
||||
* // ファイル共有メッセージ
|
||||
* local file_msg = new IntentBox("file.share", {
|
||||
* filename: "document.pdf",
|
||||
@ -32,10 +32,10 @@
|
||||
* ```
|
||||
*/
|
||||
|
||||
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
|
||||
use crate::box_trait::{BoolBox, BoxBase, BoxCore, NyashBox, StringBox};
|
||||
use std::any::Any;
|
||||
use std::sync::RwLock;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::RwLock;
|
||||
|
||||
/// IntentBox - 構造化メッセージBox (RwLock pattern)
|
||||
#[derive(Debug)]
|
||||
@ -51,7 +51,7 @@ impl Clone for IntentBox {
|
||||
fn clone(&self) -> Self {
|
||||
let name_val = self.name.read().unwrap().clone();
|
||||
let payload_val = self.payload.read().unwrap().clone();
|
||||
|
||||
|
||||
Self {
|
||||
base: BoxBase::new(), // New unique ID for clone
|
||||
name: RwLock::new(name_val),
|
||||
@ -69,19 +69,19 @@ impl IntentBox {
|
||||
payload: RwLock::new(payload),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// メッセージ名を取得
|
||||
pub fn get_name(&self) -> Box<dyn NyashBox> {
|
||||
let name = self.name.read().unwrap().clone();
|
||||
Box::new(StringBox::new(name))
|
||||
}
|
||||
|
||||
|
||||
/// ペイロードを取得
|
||||
pub fn get_payload(&self) -> Box<dyn NyashBox> {
|
||||
let payload = self.payload.read().unwrap().clone();
|
||||
Box::new(StringBox::new(payload.to_string()))
|
||||
}
|
||||
|
||||
|
||||
/// ペイロードを更新
|
||||
pub fn set_payload(&self, payload: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
|
||||
let payload_str = payload.to_string_box().value;
|
||||
@ -89,8 +89,8 @@ impl IntentBox {
|
||||
Ok(json_val) => {
|
||||
*self.payload.write().unwrap() = json_val;
|
||||
Box::new(BoolBox::new(true))
|
||||
},
|
||||
Err(_) => Box::new(BoolBox::new(false))
|
||||
}
|
||||
Err(_) => Box::new(BoolBox::new(false)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ impl NyashBox for IntentBox {
|
||||
fn clone_box(&self) -> Box<dyn NyashBox> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
|
||||
/// 仮実装: clone_boxと同じ(後で修正)
|
||||
fn share_box(&self) -> Box<dyn NyashBox> {
|
||||
self.clone_box()
|
||||
@ -109,7 +109,7 @@ impl NyashBox for IntentBox {
|
||||
let name = self.name.read().unwrap().clone();
|
||||
StringBox::new(format!("IntentBox[{}]", name))
|
||||
}
|
||||
|
||||
|
||||
fn equals(&self, other: &dyn NyashBox) -> BoolBox {
|
||||
if let Some(other_intent) = other.as_any().downcast_ref::<IntentBox>() {
|
||||
BoolBox::new(self.base.id == other_intent.base.id)
|
||||
@ -117,7 +117,7 @@ impl NyashBox for IntentBox {
|
||||
BoolBox::new(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn type_name(&self) -> &'static str {
|
||||
"IntentBox"
|
||||
}
|
||||
@ -127,7 +127,7 @@ impl BoxCore for IntentBox {
|
||||
fn box_id(&self) -> u64 {
|
||||
self.base.id
|
||||
}
|
||||
|
||||
|
||||
fn parent_type_id(&self) -> Option<std::any::TypeId> {
|
||||
self.base.parent_type_id
|
||||
}
|
||||
@ -136,11 +136,11 @@ impl BoxCore for IntentBox {
|
||||
let name = self.name.read().unwrap().clone();
|
||||
write!(f, "IntentBox[{}]", name)
|
||||
}
|
||||
|
||||
|
||||
fn as_any(&self) -> &dyn Any {
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
@ -151,4 +151,3 @@ impl std::fmt::Display for IntentBox {
|
||||
self.fmt_box(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user