Fixed task crate doc tests.

This commit is contained in:
Samuel Guerra 2023-12-02 14:20:55 -03:00
parent 032ef52877
commit f0d5407903
5 changed files with 45 additions and 33 deletions

View File

@ -66,6 +66,7 @@ TextInput! {
* Text Shaping. * Text Shaping.
- Mostly decoupled, needs l10n's Lang. - Mostly decoupled, needs l10n's Lang.
- Can use underlying type LanguageIdentifier?
* Focus. * Focus.
- Needs app API. - Needs app API.

View File

@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
[features] [features]
# # Enables parking_lot deadlock detection.
deadlock_detection = ["parking_lot/deadlock_detection"] deadlock_detection = ["parking_lot/deadlock_detection"]
# Enables http tasks. # Enables http tasks.
@ -26,6 +26,9 @@ http = [
"remove_dir_all", "remove_dir_all",
] ]
# Enabled by doc tests.
test_util = []
[dependencies] [dependencies]
zero-ui-task-proc-macros = { path = "../zero-ui-task-proc-macros" } zero-ui-task-proc-macros = { path = "../zero-ui-task-proc-macros" }
zero-ui-clone_move = { path = "../zero-ui-clone_move" } zero-ui-clone_move = { path = "../zero-ui-clone_move" }

View File

@ -8,7 +8,8 @@
//! # Examples //! # Examples
//! //!
//! ```no_run //! ```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); //! let (sender, receiver) = channel::bounded(5);
//! //!
@ -257,7 +258,8 @@ impl<T> Receiver<T> {
/// rapidly consumes all messages in the buffer and new messages as they are send. /// rapidly consumes all messages in the buffer and new messages as they are send.
/// ///
/// ```no_run /// ```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(); /// let (sender, receiver) = channel::unbounded();
/// ///
@ -306,7 +308,8 @@ pub fn unbounded<T>() -> (UnboundSender<T>, Receiver<T>) {
/// rapidly consumes the 2 messages in the buffer and unblocks the sender to send more messages. /// rapidly consumes the 2 messages in the buffer and unblocks the sender to send more messages.
/// ///
/// ```no_run /// ```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); /// let (sender, receiver) = channel::bounded(2);
/// ///
@ -352,8 +355,9 @@ pub fn bounded<T>(capacity: usize) -> (Sender<T>, Receiver<T>) {
/// receiver takes 2 seconds to receive, so the sender takes 2 seconds to send. /// receiver takes 2 seconds to receive, so the sender takes 2 seconds to send.
/// ///
/// ```no_run /// ```no_run
/// use zero_ui_core::{task::{self, channel}, units::*}; /// use zero_ui_task::{self as task, channel};
/// use std::time::*; /// # use zero_ui_units::*;
/// # use std::time::*;
/// ///
/// let (sender, receiver) = channel::rendezvous(); /// let (sender, receiver) = channel::rendezvous();
/// ///

View File

@ -12,7 +12,7 @@
//! Get some text: //! Get some text:
//! //!
//! ``` //! ```
//! # use zero_ui_core::task; //! # use zero_ui_task as task;
//! # async fn demo() -> Result<(), Box<dyn std::error::Error>> { //! # async fn demo() -> Result<(), Box<dyn std::error::Error>> {
//! let text = task::http::get_text("https://httpbin.org/base64/SGVsbG8gV29ybGQ=").await?; //! let text = task::http::get_text("https://httpbin.org/base64/SGVsbG8gV29ybGQ=").await?;
//! println!("{text}!"); //! println!("{text}!");
@ -152,7 +152,7 @@ impl Request {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http; /// use zero_ui_task::http;
/// ///
/// # fn try_example() -> Result<(), Box<dyn std::error::Error>> { /// # fn try_example() -> Result<(), Box<dyn std::error::Error>> {
/// let request = http::Request::builder().method(http::Method::PUT)?.uri("https://httpbin.org/put")?.build(); /// let request = http::Request::builder().method(http::Method::PUT)?.uri("https://httpbin.org/put")?.build();
@ -173,7 +173,7 @@ impl Request {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http; /// use zero_ui_task::http;
/// ///
/// # fn try_example() -> Result<(), Box<dyn std::error::Error>> { /// # fn try_example() -> Result<(), Box<dyn std::error::Error>> {
/// let get = http::Request::get("https://httpbin.org/get")?.build(); /// let get = http::Request::get("https://httpbin.org/get")?.build();
@ -188,7 +188,7 @@ impl Request {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http; /// use zero_ui_task::http;
/// ///
/// # fn try_example() -> Result<(), Box<dyn std::error::Error>> { /// # fn try_example() -> Result<(), Box<dyn std::error::Error>> {
/// let put = http::Request::put("https://httpbin.org/put")?.header("accept", "application/json")?.build(); /// let put = http::Request::put("https://httpbin.org/put")?.header("accept", "application/json")?.build();
@ -203,7 +203,7 @@ impl Request {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http; /// use zero_ui_task::http;
/// ///
/// # fn try_example() -> Result<(), Box<dyn std::error::Error>> { /// # fn try_example() -> Result<(), Box<dyn std::error::Error>> {
/// let post = http::Request::post("https://httpbin.org/post")?.header("accept", "application/json")?.build(); /// let post = http::Request::post("https://httpbin.org/post")?.header("accept", "application/json")?.build();
@ -218,7 +218,7 @@ impl Request {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http; /// use zero_ui_task::http;
/// ///
/// # fn try_example() -> Result<(), Box<dyn std::error::Error>> { /// # fn try_example() -> Result<(), Box<dyn std::error::Error>> {
/// let delete = http::Request::delete("https://httpbin.org/delete")?.header("accept", "application/json")?.build(); /// let delete = http::Request::delete("https://httpbin.org/delete")?.header("accept", "application/json")?.build();
@ -233,7 +233,7 @@ impl Request {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http; /// use zero_ui_task::http;
/// ///
/// # fn try_example() -> Result<(), Box<dyn std::error::Error>> { /// # fn try_example() -> Result<(), Box<dyn std::error::Error>> {
/// let patch = http::Request::patch("https://httpbin.org/patch")?.header("accept", "application/json")?.build(); /// let patch = http::Request::patch("https://httpbin.org/patch")?.header("accept", "application/json")?.build();
@ -248,7 +248,7 @@ impl Request {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http; /// use zero_ui_task::http;
/// ///
/// # fn try_example() -> Result<(), Box<dyn std::error::Error>> { /// # fn try_example() -> Result<(), Box<dyn std::error::Error>> {
/// let head = http::Request::head("https://httpbin.org")?.build(); /// let head = http::Request::head("https://httpbin.org")?.build();
@ -1473,7 +1473,7 @@ impl From<isahc::HttpClient> for Client {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// use zero_ui_core::task::http::*; /// use zero_ui_task::http::*;
/// ///
/// let client = Client::builder().metrics(true).build(); /// let client = Client::builder().metrics(true).build();
/// ``` /// ```

View File

@ -63,7 +63,7 @@
//! so we recommend blob importing [`io`] to start implementing async IO. //! 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<usize> { //! async fn read_numbers() -> Vec<usize> {
//! let mut file = fs::File::open("numbers.txt").await.unwrap(); //! let mut file = fs::File::open("numbers.txt").await.unwrap();
@ -198,7 +198,8 @@ pub use rayon_ctx::*;
/// # Examples /// # 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<usize> } /// # struct SomeStruct { sum_response: ResponseVar<usize> }
/// # impl SomeStruct { /// # impl SomeStruct {
/// fn on_event(&mut self) { /// fn on_event(&mut self) {
@ -463,7 +464,7 @@ impl<'a, 'scope: 'a> ScopeCtx<'a, 'scope> {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use zero_ui_core::{task::{self, rayon::iter::*}}; /// # use zero_ui_task::{self as task, rayon::iter::*};
/// # struct SomeStruct { sum: usize } /// # struct SomeStruct { sum: usize }
/// # async fn read_numbers() -> Vec<usize> { vec![] } /// # async fn read_numbers() -> Vec<usize> { vec![] }
/// # impl SomeStruct { /// # impl SomeStruct {
@ -593,7 +594,8 @@ where
/// # Examples /// # 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<usize> } /// # struct SomeStruct { sum_response: ResponseVar<usize> }
/// # async fn read_numbers() -> Vec<usize> { vec![] } /// # async fn read_numbers() -> Vec<usize> { vec![] }
/// # impl SomeStruct { /// # impl SomeStruct {
@ -684,7 +686,7 @@ where
/// ///
/// ``` /// ```
/// # fn main() { } /// # fn main() { }
/// # use zero_ui_core::task; /// # use zero_ui_task as task;
/// # async fn example() { /// # async fn example() {
/// task::wait(|| std::fs::read_to_string("file.txt")).await /// task::wait(|| std::fs::read_to_string("file.txt")).await
/// # ; } /// # ; }
@ -790,8 +792,8 @@ where
/// Test a [`run`] call: /// Test a [`run`] call:
/// ///
/// ``` /// ```
/// use zero_ui_core::task; /// use zero_ui_task as task;
/// # use zero_ui_core::units::*; /// # use zero_ui_units::*;
/// # async fn foo(u: u8) -> Result<u8, ()> { task::deadline(1.ms()).await; Ok(u) } /// # async fn foo(u: u8) -> Result<u8, ()> { task::deadline(1.ms()).await; Ok(u) }
/// ///
/// #[test] /// #[test]
@ -918,7 +920,8 @@ pub async fn yield_now() {
/// Await 5 seconds in a [`spawn`] parallel task: /// 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 { /// task::spawn(async {
/// println!("waiting 5 seconds.."); /// println!("waiting 5 seconds..");
@ -951,7 +954,7 @@ pub async fn deadline(deadline: impl Into<Deadline>) {
/// A future that is ready with a closure returns `Some(R)`. /// 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; /// use std::task::Poll;
/// ///
/// async fn ready_some<R>(mut closure: impl FnMut() -> Option<R>) -> R { /// async fn ready_some<R>(mut closure: impl FnMut() -> Option<R>) -> R {
@ -1015,7 +1018,7 @@ pub async fn with_deadline<O, F: Future<Output = O>>(fut: F, deadline: impl Into
/// Await for three different futures to complete: /// Await for three different futures to complete:
/// ///
/// ``` /// ```
/// use zero_ui_core::task; /// use zero_ui_task as task;
/// ///
/// # task::doc_test(false, async { /// # task::doc_test(false, async {
/// let (a, b, c) = task::all!( /// let (a, b, c) = task::all!(
@ -1148,7 +1151,8 @@ macro_rules! __all {
/// Await for the first of three futures to complete: /// 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 { /// # task::doc_test(false, async {
/// let r = task::any!( /// 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`: /// 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)] /// # #[derive(Debug, PartialEq)]
/// # pub struct FooError; /// # pub struct FooError;
/// # task::doc_test(false, async { /// # task::doc_test(false, async {
@ -1421,7 +1425,7 @@ macro_rules! __any_ok {
/// Await for the first of three futures to complete with `Some`: /// 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 { /// # task::doc_test(false, async {
/// let r = task::any_some!( /// let r = task::any_some!(
/// task::run(async { None::<char> }), /// task::run(async { None::<char> }),
@ -1559,7 +1563,7 @@ macro_rules! __any_some {
/// Await for the first of three futures to complete with `Ok(T)`: /// 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)] /// # #[derive(Debug, PartialEq)]
/// # struct FooError; /// # struct FooError;
/// # task::doc_test(false, async { /// # task::doc_test(false, async {
@ -1576,7 +1580,7 @@ macro_rules! __any_some {
/// And in if any completes with `Err(E)`: /// And in if any completes with `Err(E)`:
/// ///
/// ``` /// ```
/// use zero_ui_core::task; /// use zero_ui_task as task;
/// # #[derive(Debug, PartialEq)] /// # #[derive(Debug, PartialEq)]
/// # struct FooError; /// # struct FooError;
/// # task::doc_test(false, async { /// # task::doc_test(false, async {
@ -1720,7 +1724,7 @@ macro_rules! __all_ok {
/// Await for the first of three futures to complete with `Some`: /// 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 { /// # task::doc_test(false, async {
/// let r = task::all_some!( /// let r = task::all_some!(
/// task::run(async { Some('a') }), /// task::run(async { Some('a') }),
@ -1735,7 +1739,7 @@ macro_rules! __all_ok {
/// Completes with `None` if any future completes with `None`: /// 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 { /// # task::doc_test(false, async {
/// let r = task::all_some!( /// let r = task::all_some!(
/// task::run(async { Some('a') }), /// 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: /// 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(); /// let signal = SignalOnce::default();
/// ///