File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -44,3 +44,13 @@ pub struct Session {
44
44
/// The ID of the client device
45
45
pub device_id : DeviceIdBox ,
46
46
}
47
+
48
+ impl From < ruma:: api:: client:: r0:: session:: login:: Response > for Session {
49
+ fn from ( response : ruma:: api:: client:: r0:: session:: login:: Response ) -> Self {
50
+ Self {
51
+ access_token : response. access_token ,
52
+ user_id : response. user_id ,
53
+ device_id : response. device_id ,
54
+ }
55
+ }
56
+ }
Original file line number Diff line number Diff line change @@ -1213,6 +1213,28 @@ impl Client {
1213
1213
/// # anyhow::Result::<()>::Ok(()) });
1214
1214
/// ```
1215
1215
///
1216
+ /// The `Session` object can also be created from the response the
1217
+ /// [`Client::login()`] method returns:
1218
+ ///
1219
+ /// ```no_run
1220
+ /// use matrix_sdk::{Client, Session, ruma::{DeviceIdBox, user_id}};
1221
+ /// # use url::Url;
1222
+ /// # use futures::executor::block_on;
1223
+ /// # block_on(async {
1224
+ ///
1225
+ /// let homeserver = Url::parse("http://example.com")?;
1226
+ /// let client = Client::new(homeserver)?;
1227
+ ///
1228
+ /// let session: Session = client
1229
+ /// .login("example", "my-password", None, None)
1230
+ /// .await?
1231
+ /// .into();
1232
+ ///
1233
+ /// // Persist the `Session` so it can later be used to restore the login.
1234
+ /// // client.restore_session(session).await?;
1235
+ /// # anyhow::Result::<()>::Ok(()) });
1236
+ /// ```
1237
+ ///
1216
1238
/// [`login`]: #method.login
1217
1239
pub async fn restore_login ( & self , session : Session ) -> Result < ( ) > {
1218
1240
Ok ( self . base_client . restore_login ( session) . await ?)
You can’t perform that action at this time.
0 commit comments