Skip to main content

ferroui_reactiveui_controls/
navigation_target.rs

1//! `NavigationTarget` (`NavigationTarget.cs`): a pending navigation target.
2
3use crate::view_model_value::same_view_model_object;
4use std::any::Any;
5use std::fmt;
6use std::rc::Rc;
7
8/// A pending navigation target (`NavigationTarget`): the view model to display and the optional
9/// view contract.
10#[derive(Clone)]
11pub struct NavigationTarget {
12    /// The view model to display (`ViewModel`).
13    pub view_model: Option<Rc<dyn Any>>,
14    /// The optional view contract (`Contract`).
15    pub contract: Option<String>,
16}
17
18impl NavigationTarget {
19    /// A navigation target.
20    pub fn new(view_model: Option<Rc<dyn Any>>, contract: Option<String>) -> Self {
21        Self { view_model, contract }
22    }
23}
24
25/// The equality of the record struct: the same view model object and the same contract.
26impl PartialEq for NavigationTarget {
27    fn eq(&self, other: &Self) -> bool {
28        same_view_model_object(self.view_model.as_ref(), other.view_model.as_ref()) && self.contract == other.contract
29    }
30}
31
32impl fmt::Debug for NavigationTarget {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        f.debug_struct("NavigationTarget")
35            .field("view_model", &self.view_model.as_ref().map(|view_model| Rc::as_ptr(view_model) as *const ()))
36            .field("contract", &self.contract)
37            .finish()
38    }
39}