Skip to main content

opentalk_client_data_persistence/
opentalk_instance_account_id.rs

1// SPDX-FileCopyrightText: OpenTalk GmbH <mail@opentalk.eu>
2//
3// SPDX-License-Identifier: EUPL-1.2
4
5use crate::{opentalk_account_id::OpenTalkAccountId, opentalk_instance_id::OpenTalkInstanceId};
6
7/// The full id of a stored OpenTalk account, including the [OpenTalkInstanceId] and the [OpenTalkAccountId].
8#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct OpenTalkInstanceAccountId(OpenTalkInstanceId, OpenTalkAccountId);
10
11impl OpenTalkInstanceAccountId {
12    /// Get the instance id.
13    pub fn instance_id(&self) -> &OpenTalkInstanceId {
14        &self.0
15    }
16
17    /// Get the account id.
18    pub fn account_id(&self) -> &OpenTalkAccountId {
19        &self.1
20    }
21}
22
23impl From<(OpenTalkInstanceId, OpenTalkAccountId)> for OpenTalkInstanceAccountId {
24    fn from((instance, account): (OpenTalkInstanceId, OpenTalkAccountId)) -> Self {
25        Self(instance, account)
26    }
27}
28
29impl OpenTalkInstanceAccountId {
30    /// Convert the id to a file stem that can be used to store the account data.
31    pub fn to_file_stem(&self) -> String {
32        format!("{}_{}", self.0.to_file_name(), *self.1)
33    }
34}