Skip to main content

MapState

Trait MapState 

Source
pub trait MapState: Clone + Debug {
    // Required methods
    fn is_expandable(&self) -> bool;
    fn is_closed(&self) -> bool;
    fn closed() -> Self;
}
Expand description

Map が状態型 S に要求する制約

Map は状態の「意味」を知らない。Map が興味を持つのは2点のみ:

  • Expandable: 子ノード追加可能(フロンティアとして管理)
  • Closed: 終了(フロンティアから除外)

具体的な状態の詳細(Unexplored/Exploring/Explored/DeadEnd/Completed/Processing 等)は この trait を実装する型で自由に定義できる。Map はそれらを is_expandable() / is_closed() で抽象化して扱う。

§例: カスタム状態型

#[derive(Clone, Debug)]
enum MyState {
    Pending,      // → Expandable
    Processing,   // → neither (Map は関与しない)
    Completed,    // → Closed
    Failed,       // → Closed
}

impl MapState for MyState {
    fn is_expandable(&self) -> bool {
        matches!(self, Self::Pending)
    }
    fn is_closed(&self) -> bool {
        matches!(self, Self::Completed | Self::Failed)
    }
    fn closed() -> Self {
        Self::Completed
    }
}

Required Methods§

Source

fn is_expandable(&self) -> bool

フロンティアとして展開可能か

Source

fn is_closed(&self) -> bool

終了状態か(フロンティアから除外される)

Source

fn closed() -> Self

デフォルトの Closed 状態を返す(カスケード操作等で使用)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§