Skip to main content

opentalk_client_data_persistence/
opentalk_instance_id.rs

1// SPDX-FileCopyrightText: OpenTalk GmbH <mail@opentalk.eu>
2//
3// SPDX-License-Identifier: EUPL-1.2
4
5use serde::{Deserialize, Serialize};
6use url::Url;
7
8/// The id of an OpenTalk instance in the format of a URL.
9#[derive(
10    Debug,
11    Clone,
12    PartialEq,
13    Eq,
14    PartialOrd,
15    Ord,
16    Hash,
17    Deserialize,
18    Serialize,
19    derive_more::AsRef,
20    derive_more::Deref,
21    derive_more::From,
22    derive_more::FromStr,
23    derive_more::Into,
24)]
25pub struct OpenTalkInstanceId(Url);
26
27impl OpenTalkInstanceId {
28    /// Convert the contained URL to a string that can be used in a file name.
29    pub fn to_file_name(&self) -> String {
30        format!(
31            "{}_{}",
32            self.0.host_str().unwrap(),
33            self.0.path().replace("_", "__").replace("/", "_")
34        )
35    }
36}