feat(phase-9.75g-0): Complete BID-FFI Day 3 - FutureBox integration

- Add FutureBox BID bridge implementation for async Box types
- Support FutureBox in box_to_bid_handle conversion
- Add comprehensive FutureBox BID round-trip test
- Update CURRENT_TASK.md to reflect Day 3 completion (100%)

Day 3 fully completed! All Box types (String/Integer/Future) now integrated with BID-FFI.
Everything is Box philosophy proven through unified handle management! 🎉

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-17 20:55:49 +09:00
parent a5ff3ecafe
commit ea6cc1fe9e
3 changed files with 75 additions and 1 deletions

View File

@ -90,6 +90,12 @@ pub fn box_to_bid_handle(
arc_box.clone()
);
Ok((BidType::Handle { type_id: 2, instance_id: handle.instance_id }, handle))
} else if let Some(_future_box) = arc_box.as_any().downcast_ref::<crate::boxes::future::NyashFutureBox>() {
let handle = registry.register_box(
crate::bid::types::BoxTypeId::FutureBox as u32,
arc_box.clone()
);
Ok((BidType::Handle { type_id: 7, instance_id: handle.instance_id }, handle))
} else {
Err(BidError::InvalidType)
}
@ -199,4 +205,38 @@ mod tests {
let retrieved_value = extract_integer_value(&retrieved).unwrap();
assert_eq!(retrieved_value, 42);
}
#[test]
fn test_future_box_bid_conversion() {
let mut registry = BoxRegistry::new();
// Create FutureBox
let future_box = crate::boxes::future::NyashFutureBox::new();
let arc_box: Arc<dyn NyashBox> = Arc::new(future_box);
// Convert to BID handle
let (bid_type, handle) = box_to_bid_handle(&arc_box, &mut registry).unwrap();
assert_eq!(handle.type_id, 7); // FutureBox type ID
match bid_type {
BidType::Handle { type_id, .. } => assert_eq!(type_id, 7),
_ => panic!("Expected Handle type"),
}
// Round-trip test
let retrieved = bid_handle_to_box(handle, &registry).unwrap();
// Verify it's still a FutureBox
assert!(retrieved.as_any().downcast_ref::<crate::boxes::future::NyashFutureBox>().is_some());
// Test with result set
if let Some(future) = arc_box.as_any().downcast_ref::<crate::boxes::future::NyashFutureBox>() {
let string_result = crate::boxes::string_box::StringBox::new("Future Result");
future.set_result(Box::new(string_result));
// Verify state
assert!(future.ready());
let result = future.get();
assert_eq!(result.to_string_box().value, "Future Result");
}
}
}

View File

@ -3,6 +3,7 @@
// 参考: 既存Boxの設計思想
use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase};
use crate::bid::{BidBridge, BidHandle, BidType, BidError, BoxRegistry};
use std::any::Any;
use std::sync::RwLock;
@ -146,6 +147,25 @@ impl std::fmt::Display for NyashFutureBox {
}
}
impl BidBridge for NyashFutureBox {
fn to_bid_handle(&self, registry: &mut BoxRegistry) -> Result<BidHandle, BidError> {
use std::sync::Arc;
let arc_box: Arc<dyn NyashBox> = Arc::new(self.clone());
let handle = registry.register_box(
crate::bid::types::BoxTypeId::FutureBox as u32,
arc_box
);
Ok(handle)
}
fn bid_type(&self) -> BidType {
BidType::Handle {
type_id: crate::bid::types::BoxTypeId::FutureBox as u32,
instance_id: 0 // Will be filled by registry
}
}
}
// Export NyashFutureBox as FutureBox for consistency
pub type FutureBox = NyashFutureBox;