matrix-sdk: Add an example for the login method.

master
Damir Jelić 2020-10-06 12:01:47 +02:00
parent 45953a268c
commit e16b7f9c44
1 changed files with 19 additions and 0 deletions

View File

@ -491,6 +491,25 @@ impl Client {
/// device_id from a previous login call. Note that this should be done /// device_id from a previous login call. Note that this should be done
/// only if the client also holds the encryption keys for this device. /// only if the client also holds the encryption keys for this device.
/// ///
/// # Example
/// ```no_run
/// # use std::convert::TryFrom;
/// # use matrix_sdk::Client;
/// # use matrix_sdk::identifiers::DeviceId;
/// # use matrix_sdk_common::assign;
/// # use futures::executor::block_on;
/// # use url::Url;
/// # let homeserver = Url::parse("http://example.com").unwrap();
/// # block_on(async {
/// let client = Client::new(homeserver).unwrap();
/// let user = "example";
/// let response = client.login(user, "wordpass", None, Some("My bot")).await;
///
/// println!("Logged in as {}, got device_id {} and access_token {}",
/// user, response.device_id, response.access_token);
/// # })
/// ```
///
/// [`restore_login`]: #method.restore_login /// [`restore_login`]: #method.restore_login
#[instrument(skip(password))] #[instrument(skip(password))]
pub async fn login( pub async fn login(