From e94e2e7b2b367cbe6d9a7da03ade0f6feb58ce14 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 27 Apr 2021 01:52:02 +0200 Subject: [PATCH] client: Fix doctests by not compiling them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and move the sync example to sync's docs. --- ruma-client/src/client_api.rs | 25 +++++++++++++++++++++++++ ruma-client/src/lib.rs | 34 ++++------------------------------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/ruma-client/src/client_api.rs b/ruma-client/src/client_api.rs index e9ade5c3..5a2f5bd5 100644 --- a/ruma-client/src/client_api.rs +++ b/ruma-client/src/client_api.rs @@ -80,6 +80,31 @@ impl Client { } /// Convenience method that represents repeated calls to the sync_events endpoint as a stream. + /// + /// # Example: + /// + /// ```ignore + /// use std::time::Duration; + /// + /// # use ruma_client::Client; + /// # use ruma::presence::PresenceState; + /// # use tokio_stream::{StreamExt as _}; + /// # let homeserver_url = "https://example.com".parse().unwrap(); + /// # let client = Client::new(homeserver_url, None); + /// # let next_batch_token = String::new(); + /// # async { + /// let mut sync_stream = Box::pin(client.sync( + /// None, + /// next_batch_token, + /// &PresenceState::Online, + /// Some(Duration::from_secs(30)), + /// )); + /// while let Some(response) = sync_stream.try_next().await? { + /// // Do something with the data in the response... + /// } + /// # Result::<(), ruma_client::Error<_, _>>::Ok(()) + /// # }; + /// ``` pub fn sync<'a>( &'a self, filter: Option<&'a sync_events::Filter<'a>>, diff --git a/ruma-client/src/lib.rs b/ruma-client/src/lib.rs index afa8b570..80afe749 100644 --- a/ruma-client/src/lib.rs +++ b/ruma-client/src/lib.rs @@ -28,7 +28,7 @@ //! session rather than calling `log_in`. This can also be used to create a session for an //! application service that does not need to log in, but uses the access_token directly: //! -//! ```no_run +//! ```ignore //! use ruma_client::Client; //! //! let work = async { @@ -39,32 +39,6 @@ //! }; //! ``` //! -//! For the standard use case of synchronizing with the homeserver (i.e. getting all the latest -//! events), use the `Client::sync` method: -//! -//! ```ignore -//! use std::time::Duration; -//! -//! # use ruma_client::Client; -//! # use ruma::presence::PresenceState; -//! # use tokio_stream::{StreamExt as _}; -//! # let homeserver_url = "https://example.com".parse().unwrap(); -//! # let client = Client::new(homeserver_url, None); -//! # let next_batch_token = String::new(); -//! # async { -//! let mut sync_stream = Box::pin(client.sync( -//! None, -//! next_batch_token, -//! &PresenceState::Online, -//! Some(Duration::from_secs(30)), -//! )); -//! while let Some(response) = sync_stream.try_next().await? { -//! // Do something with the data in the response... -//! } -//! # Result::<(), ruma_client::Error<_>>::Ok(()) -//! # }; -//! ``` -//! //! The `Client` type also provides methods for registering a new account if you don't already have //! one with the given homeserver. //! @@ -74,7 +48,7 @@ //! //! For example: //! -//! ```no_run +//! ```ignore //! # use ruma_client::Client; //! # let homeserver_url = "https://example.com".parse().unwrap(); //! # let client = Client::new(homeserver_url, None); @@ -87,11 +61,11 @@ //! //! async { //! let response = client -//! .request(get_alias::Request::new(&room_alias_id!("#example_room:example.com"))) +//! .send_request(get_alias::Request::new(&room_alias_id!("#example_room:example.com"))) //! .await?; //! //! assert_eq!(response.room_id, room_id!("!n8f893n9:example.com")); -//! # Result::<(), ruma_client::Error<_>>::Ok(()) +//! # Result::<(), ruma_client::Error<_, _>>::Ok(()) //! } //! # ; //! ```