use ::std::{rc::Rc, sync::Arc};
use crate::*;
#[diagnostic::on_unimplemented(
message = "Cannot take the model of `{Self}`",
label = "no implementation for `{Self}@`"
)]
pub trait View {
type ViewTy;
#[logic]
fn view(self) -> Self::ViewTy;
}
pub use crate::base_macros::DeepModel;
pub trait DeepModel {
type DeepModelTy;
#[logic]
fn deep_model(self) -> Self::DeepModelTy;
}
impl<T: DeepModel> DeepModel for Rc<T> {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { self.view().deep_model() }
}
}
impl<T> View for Rc<T> {
type ViewTy = T;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}
impl View for str {
type ViewTy = Seq<char>;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}
impl<T: DeepModel> DeepModel for Arc<T> {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { self@.deep_model() }
}
}
impl<T> View for Arc<T> {
type ViewTy = T;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}
impl<T: DeepModel + ?Sized> DeepModel for &T {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
(*self).deep_model()
}
}
impl<T: View + ?Sized> View for &T {
type ViewTy = T::ViewTy;
#[logic]
#[open]
fn view(self) -> Self::ViewTy {
(*self).view()
}
}
impl<T: DeepModel + ?Sized> DeepModel for &mut T {
type DeepModelTy = T::DeepModelTy;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
(*self).deep_model()
}
}
impl<T: View + ?Sized> View for &mut T {
type ViewTy = T::ViewTy;
#[logic]
#[open]
fn view(self) -> Self::ViewTy {
(*self).view()
}
}
impl DeepModel for bool {
type DeepModelTy = bool;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
self
}
}
impl DeepModel for Int {
type DeepModelTy = Int;
#[logic]
#[open]
fn deep_model(self) -> Self::DeepModelTy {
self
}
}
impl View for String {
type ViewTy = Seq<char>;
#[logic]
#[trusted]
fn view(self) -> Self::ViewTy {
dead
}
}