1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Traits used to build views.
//!
//! # Views
//!
//! View is used to build HTML nodes, and since Savory is built on top of Seed,
//! views should return Seed [`Node`], the returned type can be anything
//! actually, but it's common to return single node (`Node<Msg>`) or collection
//! of nodes (`Vec<Node<Msg>>`) depending on the view type.
//!
//! Views can be any type that implement `View` trait, here is an example of
//! view type:
//!
//! Here is simple example on implementing [`View`] trait:
//! ```rust
//! # use savory::prelude::*;
//! struct HomePage;
//!
//! impl<Msg> View<Node<Msg>> for HomePage {
//! fn view(&self) -> Node<Msg> {
//! html::div().push("Home page")
//! }
//! }
//! ```
//!
//! # View Functions
//!
//! Function and closure can be used where [`View`] is expected, Savory have
//! blanket implementation for `Fn() -> T`, so we can use closure as view type:
//!
//! ```rust
//! # use savory::prelude::*;
//! let greeting = "Hello";
//! let greeting = || html::h1().push(greeting);
//! let node: Node<()> = greeting.view();
//! ```
//!
//! # View types and View functions
//!
//! View functions are simple to write and read and suitable for application
//! code, while view types works well with reusable, complex elements.
//!
//! [`View`]: crate::prelude::View
//! [`Node`]: crate::prelude::Node
use crate;
/// Main trait used to render view.