compose.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. fn main() {}
  2. struct Title(String);
  3. struct Position([f32; 3]);
  4. struct Velocity([f32; 3]);
  5. type Batch<T> = fn(&mut T) -> ();
  6. static Atom: Batch<(Title, Position, Velocity)> = |_| {};
  7. enum VNode<'a> {
  8. El(El<'a>),
  9. Text(&'a str),
  10. Fragment(&'a [VNode<'a>]),
  11. }
  12. struct El<'a> {
  13. name: &'static str,
  14. key: Option<&'a str>,
  15. attrs: &'a [(&'static str, AttrType<'a>)],
  16. children: &'a [El<'a>],
  17. }
  18. enum AttrType<'a> {
  19. Numeric(usize),
  20. Text(&'a str),
  21. }
  22. fn example() {
  23. use AttrType::Numeric;
  24. let el = El {
  25. name: "div",
  26. attrs: &[("type", Numeric(10)), ("type", Numeric(10))],
  27. key: None,
  28. children: &[],
  29. };
  30. }
  31. use dioxus::prelude::bumpalo::Bump;
  32. trait IntoVnode {
  33. fn into_vnode<'a>(self, b: &'a Bump) -> VNode<'a>;
  34. }
  35. impl<'a> IntoIterator for VNode<'a> {
  36. type Item = VNode<'a>;
  37. type IntoIter = std::iter::Once<VNode<'a>>;
  38. #[inline]
  39. fn into_iter(self) -> Self::IntoIter {
  40. std::iter::once(self)
  41. }
  42. }
  43. fn take_iterable<F: IntoVnode>(f: impl IntoIterator<Item = F>) {
  44. let iter = f.into_iter();
  45. let b = Bump::new();
  46. for f in iter {
  47. let v = f.into_vnode(&b);
  48. }
  49. }