lib.rs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #![doc = include_str!("../README.md")]
  2. #![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
  3. #![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
  4. #![warn(missing_docs)]
  5. mod any_props;
  6. mod arena;
  7. mod diff;
  8. mod dirty_scope;
  9. mod error_boundary;
  10. mod events;
  11. mod fragment;
  12. mod global_context;
  13. mod mutations;
  14. mod nodes;
  15. mod properties;
  16. mod runtime;
  17. mod scheduler;
  18. mod scope_arena;
  19. mod scope_context;
  20. mod scopes;
  21. mod virtual_dom;
  22. pub(crate) mod innerlude {
  23. pub use crate::arena::*;
  24. pub use crate::dirty_scope::*;
  25. pub use crate::error_boundary::*;
  26. pub use crate::events::*;
  27. pub use crate::fragment::*;
  28. pub use crate::global_context::*;
  29. pub use crate::mutations::*;
  30. pub use crate::nodes::*;
  31. pub use crate::properties::*;
  32. pub use crate::runtime::{Runtime, RuntimeGuard};
  33. pub use crate::scheduler::*;
  34. pub use crate::scopes::*;
  35. pub use crate::virtual_dom::*;
  36. /// An [`Element`] is a possibly-none [`VNode`] created by calling `render` on [`Scope`] or [`ScopeState`].
  37. ///
  38. /// An Errored [`Element`] will propagate the error to the nearest error boundary.
  39. pub type Element = Option<VNode>;
  40. /// A [`Component`] is a function that takes a [`Scope`] and returns an [`Element`].
  41. ///
  42. /// Components can be used in other components with two syntax options:
  43. /// - lowercase as a function call with named arguments (rust style)
  44. /// - uppercase as an element (react style)
  45. ///
  46. /// ## Rust-Style
  47. ///
  48. /// ```rust, ignore
  49. /// fn example(cx: Props) -> Element {
  50. /// // ...
  51. /// }
  52. ///
  53. /// rsx!(
  54. /// example()
  55. /// )
  56. /// ```
  57. /// ## React-Style
  58. /// ```rust, ignore
  59. /// fn Example(cx: Props) -> Element {
  60. /// // ...
  61. /// }
  62. ///
  63. /// rsx!(
  64. /// Example {}
  65. /// )
  66. /// ```
  67. pub type Component<P = ()> = fn(P) -> Element;
  68. }
  69. pub use crate::innerlude::{
  70. fc_to_builder, generation, schedule_update, schedule_update_any, use_hook, vdom_is_rendering,
  71. AnyValue, Attribute, AttributeValue, CapturedError, Component, DynamicNode, Element, ElementId,
  72. Event, Fragment, HasAttributes, IntoDynNode, Mutation, Mutations, NoOpMutations, Properties,
  73. RenderReturn, ScopeId, ScopeState, Task, Template, TemplateAttribute, TemplateNode, VComponent,
  74. VNode, VNodeInner, VPlaceholder, VText, VirtualDom, WriteMutations,
  75. };
  76. /// The purpose of this module is to alleviate imports of many common types
  77. ///
  78. /// This includes types like [`Scope`], [`Element`], and [`Component`].
  79. pub mod prelude {
  80. pub use crate::innerlude::{
  81. consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, generation,
  82. has_context, needs_update, parent_scope, provide_context, provide_root_context,
  83. push_future, remove_future, schedule_update, schedule_update_any, spawn, spawn_forever,
  84. suspend, use_error_boundary, use_hook, AnyValue, Attribute, Component, Element,
  85. ErrorBoundary, Event, EventHandler, Fragment, HasAttributes, IntoAttributeValue,
  86. IntoDynNode, Properties, Runtime, RuntimeGuard, ScopeId, ScopeState, Task, Template,
  87. TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner, VirtualDom,
  88. };
  89. }