<commit_before>use std::time::Duration;

use assign::assign;
use async_stream::try_stream;
use futures_core::stream::Stream;
use ruma_client_api::r0::{
    account::register::{self, RegistrationKind},
    session::login::{self, LoginInfo},
    sync::sync_events,
    uiaa::UserIdentifier,
};
use ruma_common::presence::PresenceState;
use ruma_identifiers::DeviceId;

use super::{Client, Error, HttpClient};

/// Client-API specific functionality of `Client`.
impl<C: HttpClient> Client<C> {
    /// Log in with a username and password.
    ///
    /// In contrast to [`send_request`][Self::send_request], this method stores the access token
    /// returned by the endpoint in this client, in addition to returning it.
    pub async fn log_in(
        &self,
        user: &str,
        password: &str,
        device_id: Option<&DeviceId>,
        initial_device_display_name: Option<&str>,
    ) -> Result<login::Response, Error<C::Error, ruma_client_api::Error>> {
        let response = self
            .send_request(assign!(
                login::Request::new(
                    LoginInfo::Password(login::Password { identifier: UserIdentifier::MatrixId(user), password })
                ), {
                    device_id,
                    initial_device_display_name,
                }
            ))
            .await?;

        *self.0.access_token.lock().unwrap() = Some(response.access_token.clone());

        Ok(response)<commit_msg>client: Use constructor for non-exhaustive LoginInfo struct<commit_after>use std::time::Duration;

use assign::assign;
use async_stream::try_stream;
use futures_core::stream::Stream;
use ruma_client_api::r0::{
    account::register::{self, RegistrationKind},
    session::login::{self, LoginInfo},
    sync::sync_events,
    uiaa::UserIdentifier,
};
use ruma_common::presence::PresenceState;
use ruma_identifiers::DeviceId;

use super::{Client, Error, HttpClient};

/// Client-API specific functionality of `Client`.
impl<C: HttpClient> Client<C> {
    /// Log in with a username and password.
    ///
    /// In contrast to [`send_request`][Self::send_request], this method stores the access token
    /// returned by the endpoint in this client, in addition to returning it.
    pub async fn log_in(
        &self,
        user: &str,
        password: &str,
        device_id: Option<&DeviceId>,
        initial_device_display_name: Option<&str>,
    ) -> Result<login::Response, Error<C::Error, ruma_client_api::Error>> {
        let response = self
            .send_request(assign!(login::Request::new(
                LoginInfo::Password(login::Password::new(UserIdentifier::MatrixId(user), password))), {
                device_id,
                initial_device_display_name,
                }
            ))
            .await?;

        *self.0.access_token.lock().unwrap() = Some(response.access_token.clone());

        Ok(response)
{'fraction_non_alphanumeric': 0.13137931034482758, 'fraction_numerical': 0.001379310344827586, 'mean_word_length': 2.930894308943089, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3087526', 'n_tokens_mistral': 831, 'n_tokens_neox': 825, 'n_words': 186}