plantuml_server_client_rs/
url.rs

1use crate::Format;
2
3/// The default URL prefix
4pub const URL_PREFIX: &str = "http://www.plantuml.com/plantuml/";
5
6/// A builder to build URLs for PlantUML server
7pub struct UrlBuilder {
8    prefix: String,
9    format: Format,
10}
11
12impl UrlBuilder {
13    /// Creates a [`UrlBuilder`] with default values.
14    pub fn new() -> Self {
15        Self {
16            prefix: URL_PREFIX.into(),
17            format: Format::Svg,
18        }
19    }
20
21    /// Creates a URL string
22    ///
23    /// * `data` - An encoded PlantUML content for GET request
24    pub fn build(self, data: String) -> String {
25        let format: &str = (&self.format).into();
26        format!("{}{format}/{data}", self.prefix)
27    }
28
29    /// Replaces URL prefix
30    pub fn prefix(self, prefix: String) -> Self {
31        Self { prefix, ..self }
32    }
33
34    /// Replaces output format
35    pub fn format(self, format: Format) -> Self {
36        Self { format, ..self }
37    }
38}
39
40impl Default for UrlBuilder {
41    fn default() -> Self {
42        Self::new()
43    }
44}