2025-12-03 07:43:08 +09:00
|
|
|
//! Phase 91: CoreServices 定義
|
|
|
|
|
//!
|
|
|
|
|
//! Ring1-Core: core_required Box の Service trait 群。
|
|
|
|
|
//! Phase 87 CoreBoxId の core_required (6個) 全てをカバー。
|
|
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
2025-12-03 07:57:21 +09:00
|
|
|
use crate::runtime::CoreBoxId;
|
2025-12-03 09:14:49 +09:00
|
|
|
use crate::box_trait::NyashBox;
|
2025-12-03 07:43:08 +09:00
|
|
|
|
|
|
|
|
/// StringBox Service trait
|
|
|
|
|
pub trait StringService: Send + Sync {
|
|
|
|
|
// Phase 92 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// IntegerBox Service trait
|
|
|
|
|
pub trait IntegerService: Send + Sync {
|
|
|
|
|
// Phase 92 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// BoolBox Service trait
|
|
|
|
|
pub trait BoolService: Send + Sync {
|
|
|
|
|
// Phase 92 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ArrayBox Service trait
|
|
|
|
|
pub trait ArrayService: Send + Sync {
|
|
|
|
|
// Phase 92 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// MapBox Service trait
|
|
|
|
|
pub trait MapService: Send + Sync {
|
|
|
|
|
// Phase 92 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ConsoleBox Service trait
|
|
|
|
|
pub trait ConsoleService: Send + Sync {
|
|
|
|
|
// Phase 92 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// CoreServices: core_required Box の集合
|
|
|
|
|
///
|
|
|
|
|
/// Phase 85 設計原則:
|
|
|
|
|
/// - core_required は必ず全て揃っていなければならない
|
|
|
|
|
/// - 起動時に全フィールドが初期化されていることを保証
|
|
|
|
|
///
|
|
|
|
|
/// Phase 87 CoreBoxId との対応:
|
|
|
|
|
/// - String → string
|
|
|
|
|
/// - Integer → integer
|
|
|
|
|
/// - Bool → bool
|
|
|
|
|
/// - Array → array
|
|
|
|
|
/// - Map → map
|
|
|
|
|
/// - Console → console
|
|
|
|
|
pub struct CoreServices {
|
|
|
|
|
pub string: Arc<dyn StringService>,
|
|
|
|
|
pub integer: Arc<dyn IntegerService>,
|
|
|
|
|
pub bool: Arc<dyn BoolService>,
|
|
|
|
|
pub array: Arc<dyn ArrayService>,
|
|
|
|
|
pub map: Arc<dyn MapService>,
|
|
|
|
|
pub console: Arc<dyn ConsoleService>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl CoreServices {
|
2025-12-03 07:57:21 +09:00
|
|
|
/// Phase 87 CoreBoxId の core_required (6個) を返す
|
|
|
|
|
///
|
|
|
|
|
/// Phase 87 CoreBoxId::is_core_required() と完全一致する。
|
|
|
|
|
pub fn required_ids() -> &'static [CoreBoxId] {
|
|
|
|
|
&[
|
|
|
|
|
CoreBoxId::String,
|
|
|
|
|
CoreBoxId::Integer,
|
|
|
|
|
CoreBoxId::Bool,
|
|
|
|
|
CoreBoxId::Array,
|
|
|
|
|
CoreBoxId::Map,
|
|
|
|
|
CoreBoxId::Console,
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 07:43:08 +09:00
|
|
|
/// 全フィールドが初期化されているか検証
|
|
|
|
|
/// Phase 92 以降で各 Service の初期化を検証
|
|
|
|
|
pub fn ensure_initialized(&self) {
|
|
|
|
|
// Phase 91 では trait が空なので何もしない
|
|
|
|
|
// Phase 92 以降で各 Service の初期化を検証
|
|
|
|
|
}
|
2025-12-03 08:42:45 +09:00
|
|
|
|
2025-12-03 09:14:49 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Phase 94: Adapter Pattern - Box → Service 変換
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
/// StringBox → StringService Adapter
|
|
|
|
|
pub struct StringBoxAdapter {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
inner: Box<dyn NyashBox>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl StringBoxAdapter {
|
|
|
|
|
pub fn new(box_instance: Box<dyn NyashBox>) -> Self {
|
|
|
|
|
Self { inner: box_instance }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl StringService for StringBoxAdapter {
|
|
|
|
|
// Phase 95 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// IntegerBox → IntegerService Adapter
|
|
|
|
|
pub struct IntegerBoxAdapter {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
inner: Box<dyn NyashBox>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl IntegerBoxAdapter {
|
|
|
|
|
pub fn new(box_instance: Box<dyn NyashBox>) -> Self {
|
|
|
|
|
Self { inner: box_instance }
|
2025-12-03 08:42:45 +09:00
|
|
|
}
|
2025-12-03 07:43:08 +09:00
|
|
|
}
|
2025-12-03 07:57:21 +09:00
|
|
|
|
2025-12-03 09:14:49 +09:00
|
|
|
impl IntegerService for IntegerBoxAdapter {
|
|
|
|
|
// Phase 95 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// BoolBox → BoolService Adapter
|
|
|
|
|
pub struct BoolBoxAdapter {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
inner: Box<dyn NyashBox>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl BoolBoxAdapter {
|
|
|
|
|
pub fn new(box_instance: Box<dyn NyashBox>) -> Self {
|
|
|
|
|
Self { inner: box_instance }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl BoolService for BoolBoxAdapter {
|
|
|
|
|
// Phase 95 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ArrayBox → ArrayService Adapter
|
|
|
|
|
pub struct ArrayBoxAdapter {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
inner: Box<dyn NyashBox>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ArrayBoxAdapter {
|
|
|
|
|
pub fn new(box_instance: Box<dyn NyashBox>) -> Self {
|
|
|
|
|
Self { inner: box_instance }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ArrayService for ArrayBoxAdapter {
|
|
|
|
|
// Phase 95 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// MapBox → MapService Adapter
|
|
|
|
|
pub struct MapBoxAdapter {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
inner: Box<dyn NyashBox>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MapBoxAdapter {
|
|
|
|
|
pub fn new(box_instance: Box<dyn NyashBox>) -> Self {
|
|
|
|
|
Self { inner: box_instance }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl MapService for MapBoxAdapter {
|
|
|
|
|
// Phase 95 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// ConsoleBox → ConsoleService Adapter
|
|
|
|
|
pub struct ConsoleBoxAdapter {
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
inner: Box<dyn NyashBox>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ConsoleBoxAdapter {
|
|
|
|
|
pub fn new(box_instance: Box<dyn NyashBox>) -> Self {
|
|
|
|
|
Self { inner: box_instance }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ConsoleService for ConsoleBoxAdapter {
|
|
|
|
|
// Phase 95 以降で実装
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 07:57:21 +09:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_required_ids_consistency() {
|
|
|
|
|
let required = CoreServices::required_ids();
|
|
|
|
|
assert_eq!(required.len(), 6);
|
|
|
|
|
|
|
|
|
|
// Phase 87 CoreBoxId::is_core_required() と一致
|
|
|
|
|
for id in required {
|
|
|
|
|
assert!(id.is_core_required());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 全ての core_required が含まれているか確認
|
|
|
|
|
assert!(required.contains(&CoreBoxId::String));
|
|
|
|
|
assert!(required.contains(&CoreBoxId::Integer));
|
|
|
|
|
assert!(required.contains(&CoreBoxId::Bool));
|
|
|
|
|
assert!(required.contains(&CoreBoxId::Array));
|
|
|
|
|
assert!(required.contains(&CoreBoxId::Map));
|
|
|
|
|
assert!(required.contains(&CoreBoxId::Console));
|
|
|
|
|
}
|
|
|
|
|
}
|