client: Fix doctests by not compiling them

… and move the sync example to sync's docs.
This commit is contained in:
Jonas Platte 2021-04-27 01:52:02 +02:00
parent c692d18797
commit e94e2e7b2b
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
2 changed files with 29 additions and 30 deletions

View File

@ -80,6 +80,31 @@ impl<C: HttpClient> Client<C> {
}
/// 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>>,

View File

@ -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(())
//! }
//! # ;
//! ```