lib.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. mod usestate;
  2. pub use usestate::{use_state, UseState};
  3. mod useref;
  4. pub use useref::*;
  5. mod use_shared_state;
  6. pub use use_shared_state::*;
  7. mod usecoroutine;
  8. pub use usecoroutine::*;
  9. mod usefuture;
  10. pub use usefuture::*;
  11. mod usesuspense;
  12. pub use usesuspense::*;
  13. #[macro_export]
  14. macro_rules! to_owned {
  15. ($($es:ident),+) => {$(
  16. #[allow(unused_mut)]
  17. let mut $es = $es.to_owned();
  18. )*}
  19. }
  20. /// Calls `for_async` on the series of paramters.
  21. ///
  22. /// If the type is Clone, then it will be cloned. However, if the type is not `clone`
  23. /// then it must have a `for_async` method for Rust to lower down into.
  24. ///
  25. /// See: how use_state implements `for_async` but *not* through the trait.
  26. #[macro_export]
  27. macro_rules! for_async {
  28. ($($es:ident),+) => {$(
  29. #[allow(unused_mut)]
  30. let mut $es = $es.for_async();
  31. )*}
  32. }
  33. /// This is a marker trait that uses decoherence.
  34. ///
  35. /// It is *not* meant for hooks to actually implement, but rather defer to their
  36. /// underlying implementation if they *don't* implement the trait.
  37. ///
  38. ///
  39. pub trait AsyncHook {
  40. type Output;
  41. fn for_async(self) -> Self::Output;
  42. }
  43. impl<T> AsyncHook for T
  44. where
  45. T: ToOwned<Owned = T>,
  46. {
  47. type Output = T;
  48. fn for_async(self) -> Self::Output {
  49. self
  50. }
  51. }