diff --git a/TODO/_current.md b/TODO/_current.md index 3e4a2a7cf..2b02c095d 100644 --- a/TODO/_current.md +++ b/TODO/_current.md @@ -66,6 +66,7 @@ TextInput! { * Text Shaping. - Mostly decoupled, needs l10n's Lang. + - Can use underlying type LanguageIdentifier? * Focus. - Needs app API. diff --git a/zero-ui-task/Cargo.toml b/zero-ui-task/Cargo.toml index 6c4bd308b..407d61c75 100644 --- a/zero-ui-task/Cargo.toml +++ b/zero-ui-task/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" license = "Apache-2.0" [features] -# +# Enables parking_lot deadlock detection. deadlock_detection = ["parking_lot/deadlock_detection"] # Enables http tasks. @@ -26,6 +26,9 @@ http = [ "remove_dir_all", ] +# Enabled by doc tests. +test_util = [] + [dependencies] zero-ui-task-proc-macros = { path = "../zero-ui-task-proc-macros" } zero-ui-clone_move = { path = "../zero-ui-clone_move" } diff --git a/zero-ui-task/src/channel.rs b/zero-ui-task/src/channel.rs index b742508d6..912a57b5a 100644 --- a/zero-ui-task/src/channel.rs +++ b/zero-ui-task/src/channel.rs @@ -8,7 +8,8 @@ //! # Examples //! //! ```no_run -//! use zero_ui_core::{task::{self, channel}, units::*}; +//! use zero_ui_task::{self as task, channel}; +//! # use zero_ui_units::*; //! //! let (sender, receiver) = channel::bounded(5); //! @@ -257,7 +258,8 @@ impl Receiver { /// rapidly consumes all messages in the buffer and new messages as they are send. /// /// ```no_run -/// use zero_ui_core::{task::{self, channel}, units::*}; +/// use zero_ui_task::{self as task, channel}; +/// # use zero_ui_units::*; /// /// let (sender, receiver) = channel::unbounded(); /// @@ -306,7 +308,8 @@ pub fn unbounded() -> (UnboundSender, Receiver) { /// rapidly consumes the 2 messages in the buffer and unblocks the sender to send more messages. /// /// ```no_run -/// use zero_ui_core::{task::{self, channel}, units::*}; +/// use zero_ui_task::{self as task, channel}; +/// # use zero_ui_units::*; /// /// let (sender, receiver) = channel::bounded(2); /// @@ -352,8 +355,9 @@ pub fn bounded(capacity: usize) -> (Sender, Receiver) { /// receiver takes 2 seconds to receive, so the sender takes 2 seconds to send. /// /// ```no_run -/// use zero_ui_core::{task::{self, channel}, units::*}; -/// use std::time::*; +/// use zero_ui_task::{self as task, channel}; +/// # use zero_ui_units::*; +/// # use std::time::*; /// /// let (sender, receiver) = channel::rendezvous(); /// diff --git a/zero-ui-task/src/http.rs b/zero-ui-task/src/http.rs index 50aa537d1..1779b3715 100644 --- a/zero-ui-task/src/http.rs +++ b/zero-ui-task/src/http.rs @@ -12,7 +12,7 @@ //! Get some text: //! //! ``` -//! # use zero_ui_core::task; +//! # use zero_ui_task as task; //! # async fn demo() -> Result<(), Box> { //! let text = task::http::get_text("https://httpbin.org/base64/SGVsbG8gV29ybGQ=").await?; //! println!("{text}!"); @@ -152,7 +152,7 @@ impl Request { /// # Examples /// /// ``` - /// use zero_ui_core::task::http; + /// use zero_ui_task::http; /// /// # fn try_example() -> Result<(), Box> { /// let request = http::Request::builder().method(http::Method::PUT)?.uri("https://httpbin.org/put")?.build(); @@ -173,7 +173,7 @@ impl Request { /// # Examples /// /// ``` - /// use zero_ui_core::task::http; + /// use zero_ui_task::http; /// /// # fn try_example() -> Result<(), Box> { /// let get = http::Request::get("https://httpbin.org/get")?.build(); @@ -188,7 +188,7 @@ impl Request { /// # Examples /// /// ``` - /// use zero_ui_core::task::http; + /// use zero_ui_task::http; /// /// # fn try_example() -> Result<(), Box> { /// let put = http::Request::put("https://httpbin.org/put")?.header("accept", "application/json")?.build(); @@ -203,7 +203,7 @@ impl Request { /// # Examples /// /// ``` - /// use zero_ui_core::task::http; + /// use zero_ui_task::http; /// /// # fn try_example() -> Result<(), Box> { /// let post = http::Request::post("https://httpbin.org/post")?.header("accept", "application/json")?.build(); @@ -218,7 +218,7 @@ impl Request { /// # Examples /// /// ``` - /// use zero_ui_core::task::http; + /// use zero_ui_task::http; /// /// # fn try_example() -> Result<(), Box> { /// let delete = http::Request::delete("https://httpbin.org/delete")?.header("accept", "application/json")?.build(); @@ -233,7 +233,7 @@ impl Request { /// # Examples /// /// ``` - /// use zero_ui_core::task::http; + /// use zero_ui_task::http; /// /// # fn try_example() -> Result<(), Box> { /// let patch = http::Request::patch("https://httpbin.org/patch")?.header("accept", "application/json")?.build(); @@ -248,7 +248,7 @@ impl Request { /// # Examples /// /// ``` - /// use zero_ui_core::task::http; + /// use zero_ui_task::http; /// /// # fn try_example() -> Result<(), Box> { /// let head = http::Request::head("https://httpbin.org")?.build(); @@ -1473,7 +1473,7 @@ impl From for Client { /// # Examples /// /// ``` -/// use zero_ui_core::task::http::*; +/// use zero_ui_task::http::*; /// /// let client = Client::builder().metrics(true).build(); /// ``` diff --git a/zero-ui-task/src/lib.rs b/zero-ui-task/src/lib.rs index 22596badf..8a5a21b46 100644 --- a/zero-ui-task/src/lib.rs +++ b/zero-ui-task/src/lib.rs @@ -63,7 +63,7 @@ //! so we recommend blob importing [`io`] to start implementing async IO. //! //! ``` -//! use zero_ui_core::task::{io::*, fs, rayon::prelude::*}; +//! use zero_ui_task::{io::*, fs, rayon::prelude::*}; //! //! async fn read_numbers() -> Vec { //! let mut file = fs::File::open("numbers.txt").await.unwrap(); @@ -198,7 +198,8 @@ pub use rayon_ctx::*; /// # Examples /// /// ``` -/// # use zero_ui_core::{task::{self, rayon::iter::*}, var::{ResponseVar, response_var}}; +/// # use zero_ui_task::{self as task, *, rayon::iter::*}; +/// # use zero_ui_var::*; /// # struct SomeStruct { sum_response: ResponseVar } /// # impl SomeStruct { /// fn on_event(&mut self) { @@ -463,7 +464,7 @@ impl<'a, 'scope: 'a> ScopeCtx<'a, 'scope> { /// # Examples /// /// ``` -/// # use zero_ui_core::{task::{self, rayon::iter::*}}; +/// # use zero_ui_task::{self as task, rayon::iter::*}; /// # struct SomeStruct { sum: usize } /// # async fn read_numbers() -> Vec { vec![] } /// # impl SomeStruct { @@ -593,7 +594,8 @@ where /// # Examples /// /// ``` -/// # use zero_ui_core::{task::{self, rayon::iter::*}, var::ResponseVar}; +/// # use zero_ui_task::{self as task, rayon::iter::*}; +/// # use zero_ui_var::*; /// # struct SomeStruct { sum_response: ResponseVar } /// # async fn read_numbers() -> Vec { vec![] } /// # impl SomeStruct { @@ -684,7 +686,7 @@ where /// /// ``` /// # fn main() { } -/// # use zero_ui_core::task; +/// # use zero_ui_task as task; /// # async fn example() { /// task::wait(|| std::fs::read_to_string("file.txt")).await /// # ; } @@ -790,8 +792,8 @@ where /// Test a [`run`] call: /// /// ``` -/// use zero_ui_core::task; -/// # use zero_ui_core::units::*; +/// use zero_ui_task as task; +/// # use zero_ui_units::*; /// # async fn foo(u: u8) -> Result { task::deadline(1.ms()).await; Ok(u) } /// /// #[test] @@ -918,7 +920,8 @@ pub async fn yield_now() { /// Await 5 seconds in a [`spawn`] parallel task: /// /// ``` -/// use zero_ui_core::{task, units::*}; +/// use zero_ui_task as task; +/// use zero_ui_units::*; /// /// task::spawn(async { /// println!("waiting 5 seconds.."); @@ -951,7 +954,7 @@ pub async fn deadline(deadline: impl Into) { /// A future that is ready with a closure returns `Some(R)`. /// /// ``` -/// use zero_ui_core::task; +/// use zero_ui_task as task; /// use std::task::Poll; /// /// async fn ready_some(mut closure: impl FnMut() -> Option) -> R { @@ -1015,7 +1018,7 @@ pub async fn with_deadline>(fut: F, deadline: impl Into /// Await for three different futures to complete: /// /// ``` -/// use zero_ui_core::task; +/// use zero_ui_task as task; /// /// # task::doc_test(false, async { /// let (a, b, c) = task::all!( @@ -1148,7 +1151,8 @@ macro_rules! __all { /// Await for the first of three futures to complete: /// /// ``` -/// use zero_ui_core::{task, units::*}; +/// use zero_ui_task as task; +/// use zero_ui_units::*; /// /// # task::doc_test(false, async { /// let r = task::any!( @@ -1276,7 +1280,7 @@ pub use zero_ui_task_proc_macros::task_any_all as __proc_any_all; /// Await for the first of three futures to complete with `Ok`: /// /// ``` -/// use zero_ui_core::task; +/// use zero_ui_task as task; /// # #[derive(Debug, PartialEq)] /// # pub struct FooError; /// # task::doc_test(false, async { @@ -1421,7 +1425,7 @@ macro_rules! __any_ok { /// Await for the first of three futures to complete with `Some`: /// /// ``` -/// use zero_ui_core::task; +/// use zero_ui_task as task; /// # task::doc_test(false, async { /// let r = task::any_some!( /// task::run(async { None:: }), @@ -1559,7 +1563,7 @@ macro_rules! __any_some { /// Await for the first of three futures to complete with `Ok(T)`: /// /// ``` -/// use zero_ui_core::task; +/// use zero_ui_task as task; /// # #[derive(Debug, PartialEq)] /// # struct FooError; /// # task::doc_test(false, async { @@ -1576,7 +1580,7 @@ macro_rules! __any_some { /// And in if any completes with `Err(E)`: /// /// ``` -/// use zero_ui_core::task; +/// use zero_ui_task as task; /// # #[derive(Debug, PartialEq)] /// # struct FooError; /// # task::doc_test(false, async { @@ -1720,7 +1724,7 @@ macro_rules! __all_ok { /// Await for the first of three futures to complete with `Some`: /// /// ``` -/// use zero_ui_core::task; +/// use zero_ui_task as task; /// # task::doc_test(false, async { /// let r = task::all_some!( /// task::run(async { Some('a') }), @@ -1735,7 +1739,7 @@ macro_rules! __all_ok { /// Completes with `None` if any future completes with `None`: /// /// ``` -/// # use zero_ui_core::task; +/// # use zero_ui_task as task; /// # task::doc_test(false, async { /// let r = task::all_some!( /// task::run(async { Some('a') }), @@ -1864,7 +1868,7 @@ macro_rules! __all_some { /// Spawns a parallel task that only writes to stdout after the main thread sets the signal: /// /// ``` -/// use zero_ui_core::task::{self, *}; +/// use zero_ui_task::{self as task, *}; /// /// let signal = SignalOnce::default(); ///