phlow 3.0.0

An engine for scripting reactive browsers in Rust by adding custom views to structures
Documentation
#[macro_use]
extern crate phlow;

use phlow::view_functions_of_val;
use std::fmt::{Display, Formatter};

environment!();

#[derive(Debug, RawView)]
pub struct Person {
    name: String,
    age: usize,
    address: Address,
}

#[derive(Debug)]
pub struct Address {
    city: String,
    country: String,
}

impl Display for Address {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.city.as_str())?;
        f.write_str(", ")?;
        f.write_str(self.country.as_str())?;
        Ok(())
    }
}

#[extensions(Person)]
mod person_extensions {
    use super::*;
    use phlow::{InfoRow, PhlowView, ProtoView};

    #[view]
    fn info_for(_person: &Person, view: impl ProtoView<Person>) -> impl PhlowView {
        view.info()
            .title("Info")
            .priority(1)
            .row(|row| {
                row.named_str("name")
                    .item_ref(|value| &value.name)
                    .text(|item| to_string!(item))
            })
            .row(|row| {
                row.named_str("age")
                    .item_ref(|value| &value.age)
                    .text(|item| to_string!(item))
            })
            .row(|row| {
                row.named_str("address")
                    .item_ref(|value| &value.address)
                    .text(|item| to_string!(item))
            })
    }
}

pub fn main() {
    let person = Person {
        name: "Alice".to_string(),
        age: 27,
        address: Address {
            city: "Paris".to_string(),
            country: "France".to_string(),
        },
    };

    let view_method = view_functions_of_val(&person)
        .into_iter()
        .find(|f| f.name() == "raw_for")
        .unwrap();

    let _view = view_method.as_view(&person);
}