htsget-config 0.22.0

Used to configure htsget-rs by using a config file or reading environment variables.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
//! Storage location configuration.
//!

use crate::config::advanced::regex_location::RegexLocation;
use crate::config::service_info::PackageInfo;
use crate::error::{Error::ParseError, Result};
use crate::storage::Backend;
#[cfg(feature = "experimental")]
use crate::storage::c4gh::C4GHKeys;
use crate::storage::file::default_authority;
use crate::types::Scheme;
use crate::{error, storage};
use cfg_if::cfg_if;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[cfg(feature = "url")]
use {crate::config::advanced::url::Url, http::Uri, http::uri::InvalidUri};

/// The locations of data.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(default, deny_unknown_fields, from = "LocationsOneOrMany")]
pub struct Locations(Vec<Location>);

impl Locations {
  /// Create new locations.
  pub fn new(locations: Vec<Location>) -> Self {
    Self(locations)
  }

  /// Get locations as a slice of `LocationEither`.
  pub fn as_slice(&self) -> &[Location] {
    self.0.as_slice()
  }

  /// Get locations as an owned vector of `LocationEither`.
  pub fn into_inner(self) -> Vec<Location> {
    self.0
  }

  /// Get locations as a mutable slice of `LocationEither`.
  pub fn as_mut_slice(&mut self) -> &mut [Location] {
    self.0.as_mut_slice()
  }

  /// Set the user-agent information from the package info.
  pub fn set_from_package_info(&mut self, _info: &PackageInfo) -> Result<()> {
    #[cfg(feature = "url")]
    for location in self.as_mut_slice() {
      if let Ok(url) = location.backend_mut().as_url_mut() {
        let client = url.inner_client_mut();
        let builder = client.take_config()?;
        client.set_config(builder.with_user_agent(_info.id.to_string()));
      }
    }

    Ok(())
  }
}

impl Default for Locations {
  fn default() -> Self {
    Self(vec![Default::default()])
  }
}

impl From<Vec<Location>> for Locations {
  fn from(locations: Vec<Location>) -> Self {
    Self::new(locations)
  }
}

/// Either simple or regex based location.
#[derive(JsonSchema, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(untagged, deny_unknown_fields)]
pub enum Location {
  /// Use a simple location.
  Simple(Box<SimpleLocation>),
  /// Use a regex location.
  Regex(Box<RegexLocation>),
}

impl Location {
  /// Get the storage backend.
  pub fn backend(&self) -> &Backend {
    match self {
      Location::Simple(location) => location.backend(),
      Location::Regex(regex_location) => regex_location.backend(),
    }
  }

  /// Get the storage backend as a mutable reference.
  pub fn backend_mut(&mut self) -> &mut Backend {
    match self {
      Location::Simple(location) => location.backend_mut(),
      Location::Regex(regex_location) => regex_location.backend_mut(),
    }
  }

  /// Take the backend from the location.
  pub fn into_backend(self) -> Backend {
    match self {
      Location::Simple(location) => location.into_backend(),
      Location::Regex(location) => location.into_backend(),
    }
  }

  /// Get the simple location variant, returning an error otherwise.
  pub fn as_simple(&self) -> Result<&SimpleLocation> {
    if let Location::Simple(simple) = self {
      Ok(simple)
    } else {
      Err(ParseError("not a `Simple` variant".to_string()))
    }
  }

  /// Get the regex location variant, returning an error otherwise.
  pub fn as_regex(&self) -> Result<&RegexLocation> {
    if let Location::Regex(regex) = self {
      Ok(regex)
    } else {
      Err(ParseError("not a `Regex` variant".to_string()))
    }
  }
}

impl Default for Location {
  fn default() -> Self {
    Self::Simple(Default::default())
  }
}

/// Whether the location specifies a prefix or an exact match id.
#[derive(JsonSchema, Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(deny_unknown_fields, rename_all = "lowercase")]
pub enum PrefixOrId {
  /// Use prefix matching logic, where the requested id should start with the prefix.
  Prefix(String),
  /// Use exact id matching logic, where the requested id should be equal to this id.
  Id(String),
}

impl PrefixOrId {
  /// Convert to a prefix if the variant is a prefix.
  pub fn as_prefix(&self) -> Option<&str> {
    match self {
      PrefixOrId::Prefix(prefix) => Some(prefix),
      PrefixOrId::Id(_) => None,
    }
  }

  /// Convert to an id if the variant is an id.
  pub fn as_id(&self) -> Option<&str> {
    match self {
      PrefixOrId::Prefix(_) => None,
      PrefixOrId::Id(id) => Some(id),
    }
  }
}

impl Default for PrefixOrId {
  fn default() -> Self {
    Self::Prefix(Default::default())
  }
}

/// A simple location config.
#[derive(JsonSchema, Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq)]
#[serde(
  try_from = "LocationWrapper",
  into = "LocationWrapper",
  deny_unknown_fields
)]
pub struct SimpleLocation {
  backend: Backend,
  to_append: String,
  prefix_or_id: Option<PrefixOrId>,
}

impl SimpleLocation {
  /// Create a new location.
  pub fn new(backend: Backend, to_append: String, prefix_or_id: Option<PrefixOrId>) -> Self {
    Self {
      backend,
      to_append,
      prefix_or_id,
    }
  }

  /// Get the storage backend.
  pub fn backend(&self) -> &Backend {
    &self.backend
  }

  /// Get the storage backend as a mutable reference
  pub fn backend_mut(&mut self) -> &mut Backend {
    &mut self.backend
  }

  /// Get the prefix or id.
  pub fn prefix_or_id(&self) -> Option<PrefixOrId> {
    self.prefix_or_id.clone()
  }

  /// Get the additional path to append to resolve the id.
  pub fn to_append(&self) -> &str {
    &self.to_append
  }

  /// Take the backend from the location.
  pub fn into_backend(self) -> Backend {
    self.backend
  }
}

/// Either a single or many locations
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged, deny_unknown_fields)]
enum LocationsOneOrMany {
  Many(Vec<Location>),
  One(Box<Location>),
}

impl From<LocationsOneOrMany> for Locations {
  fn from(locations: LocationsOneOrMany) -> Self {
    match locations {
      LocationsOneOrMany::One(location) => Self(vec![*location]),
      LocationsOneOrMany::Many(locations) => Self(locations),
    }
  }
}

/// Deserialize into a string location that also supports setting additional fields
/// for the backend.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(default, deny_unknown_fields)]
struct ExtendedLocation {
  #[serde(flatten, alias = "backend")]
  location: StringLocation,
  #[cfg(feature = "experimental")]
  #[serde(skip_serializing)]
  keys: Option<C4GHKeys>,
}

/// Deserialize the location from a string with a protocol and either a prefix or exact id match logic.
#[derive(JsonSchema, Deserialize, Serialize, Debug, Clone, Default)]
#[serde(default, deny_unknown_fields)]
struct StringLocation {
  /// The location, which should start with `file://`, `s3://`, `http://` or `https://`.
  #[serde(alias = "backend")]
  location: Option<String>,
  /// The prefix or id match configuration.
  #[serde(flatten)]
  prefix_or_id: PrefixOrId,
}

/// Deserialize the location from a map with regular field and values.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[serde(default, deny_unknown_fields)]
struct MapLocation {
  #[serde(alias = "backend")]
  location: Backend,
  append_to: String,
  prefix_or_id: Option<PrefixOrId>,
}

/// A wrapper around location deserialization that can deserialize either a string
/// or a map. This is required so that default values behave correctly when deserializing
/// the `Location`. For example, if a location string isn't specified, the `Deserialize`
/// implementation for `StringLocation` can't account for this as it gets passed default values
/// which contain map elements. This wrapper allows deserializing using regular semantics by
/// falling back to the regular `MapLocation` derived deserializer. The reason there needs to be a
/// `StringLocation` and `MapLocation` type is so that `Location` can be deserialized using the
/// `from` attribute without recursion.
#[derive(JsonSchema, Serialize, Deserialize, Debug, Clone)]
#[serde(untagged, deny_unknown_fields)]
enum LocationWrapper {
  #[schemars(skip)]
  SingleLocation(String),
  String(StringLocation),
  #[schemars(skip)]
  Map(Box<MapLocation>),
  #[schemars(skip)]
  Extended(ExtendedLocation),
}

impl From<SimpleLocation> for LocationWrapper {
  fn from(location: SimpleLocation) -> Self {
    LocationWrapper::Map(Box::from(MapLocation {
      location: location.backend,
      append_to: location.to_append,
      prefix_or_id: location.prefix_or_id,
    }))
  }
}

impl TryFrom<LocationWrapper> for SimpleLocation {
  type Error = error::Error;

  fn try_from(location: LocationWrapper) -> Result<Self> {
    match location {
      LocationWrapper::SingleLocation(location) => {
        let backend: BackendWithAppend = location.try_into()?;
        Ok(SimpleLocation::new(backend.0, backend.1, None))
      }
      LocationWrapper::String(wrapper) => {
        let location = wrapper.location.unwrap_or_default();
        let backend: BackendWithAppend = if location.is_empty() {
          Default::default()
        } else {
          location.try_into()?
        };
        Ok(SimpleLocation::new(
          backend.0,
          backend.1,
          Some(wrapper.prefix_or_id),
        ))
      }
      LocationWrapper::Map(wrapper) => Ok(SimpleLocation::new(
        wrapper.location,
        wrapper.append_to,
        wrapper.prefix_or_id,
      )),
      LocationWrapper::Extended(wrapper) => {
        cfg_if! {
          if #[cfg(feature = "experimental")] {
            let mut backend: BackendWithAppend = wrapper.location.location.unwrap_or_default().try_into()?;
            backend.0.set_keys(wrapper.keys);
            Ok(SimpleLocation::new(backend.0, backend.1, Some(wrapper.location.prefix_or_id)))
          } else {
            let backend: BackendWithAppend = wrapper.location.location.unwrap_or_default().try_into()?;
            Ok(SimpleLocation::new(backend.0, backend.1, Some(wrapper.location.prefix_or_id)))
          }
        }
      }
    }
  }
}

impl From<SimpleLocation> for Location {
  fn from(location: SimpleLocation) -> Self {
    Self::Simple(Box::new(location))
  }
}

/// Extracts the backend and the additional path that needs to be appended to resolve the id.
#[derive(Debug, Default)]
struct BackendWithAppend(Backend, String);

impl TryFrom<String> for BackendWithAppend {
  type Error = error::Error;

  fn try_from(s: String) -> Result<Self> {
    let split = |s: &str| {
      let (s1, s2) = if let Some(split) = s
        .split_once("/")
        .map(|(s1, s2)| (s1.to_string(), s2.to_string()))
      {
        split
      } else {
        (s.to_string(), "".to_string())
      };

      if s1.is_empty() {
        Err(ParseError("cannot have empty location".to_string()))
      } else {
        Ok((s1, s2))
      }
    };

    if let Some(s) = s.strip_prefix("file://") {
      let (path, to_append) = split(s)?;

      let mut file = storage::file::File::new(Scheme::Http, default_authority(), path.to_string());
      // Origin should be updated based on data server config.
      file.is_defaulted = true;

      return Ok(BackendWithAppend(Backend::File(file), to_append));
    }

    #[cfg(feature = "aws")]
    if let Some(s) = s.strip_prefix("s3://") {
      let (bucket, to_append) = split(s)?;

      return Ok(BackendWithAppend(
        Backend::S3(storage::s3::S3::new(bucket.to_string(), None, false)),
        to_append,
      ));
    }

    #[cfg(feature = "url")]
    if let Some(s_stripped) = s
      .strip_prefix("http://")
      .or_else(|| s.strip_prefix("https://"))
    {
      let (mut uri, to_append) = split(s_stripped)?;

      if s.starts_with("http://") {
        uri = format!("http://{s_stripped}");
      }
      if s.starts_with("https://") {
        uri = format!("https://{s_stripped}");
      }

      let uri: Uri = uri
        .parse()
        .map_err(|err: InvalidUri| error::Error::ParseError(err.to_string()))?;
      let url = Url::new(
        uri.clone(),
        Some(uri),
        vec!["*".to_string()],
        vec![],
        vec!["*".to_string()],
        vec![],
        Default::default(),
      )
      .try_into()?;

      return Ok(BackendWithAppend(Backend::Url(Box::new(url)), to_append));
    }

    Err(ParseError(
      "expected file://, s3://, http:// or https:// scheme".to_string(),
    ))
  }
}

#[cfg(test)]
mod tests {
  use super::*;
  use crate::config::Config;
  use crate::config::tests::test_serialize_and_deserialize;
  use std::result;

  #[test]
  fn location_single() {
    test_serialize_and_deserialize(
      r#"
      locations = "file://path/prefix1"
      "#,
      ("path".to_string(), "prefix1".to_string(), None),
      |result: Config| assert_file_location(result),
    );
    test_serialize_and_deserialize(
      r#"
      locations = "file://path/prefix1/"
      "#,
      ("path".to_string(), "prefix1/".to_string(), None),
      |result: Config| assert_file_location(result),
    );
  }

  #[test]
  fn location_no_prefix() {
    test_serialize_and_deserialize(
      r#"
      locations = "file://path"
      "#,
      ("path".to_string(), "".to_string(), None),
      |result: Config| assert_file_location(result),
    );
    test_serialize_and_deserialize(
      r#"
      locations = "file://path/"
      "#,
      ("path".to_string(), "".to_string(), None),
      |result: Config| assert_file_location(result),
    );
  }

  #[test]
  fn location_file() {
    test_serialize_and_deserialize(
      r#"
      locations = [ { location = "file://path", prefix = "prefix1" }, { location = "file://path", prefix = "prefix2" } ]
      "#,
      (
        "path".to_string(),
        "prefix1".to_string(),
        "path".to_string(),
        "prefix2".to_string(),
      ),
      |result: Config| {
        let result = result.locations.0;
        assert_eq!(result.len(), 2);
        if let (Location::Simple(location1), Location::Simple(location2)) =
          (result.first().unwrap(), result.get(1).unwrap())
        {
          let file1 = location1.backend().as_file().unwrap();
          let file2 = location2.backend().as_file().unwrap();

          return (
            file1.local_path().to_string(),
            location1
              .prefix_or_id()
              .unwrap()
              .as_prefix()
              .unwrap()
              .to_string(),
            file2.local_path().to_string(),
            location2
              .prefix_or_id()
              .unwrap()
              .as_prefix()
              .unwrap()
              .to_string(),
          );
        }

        panic!();
      },
    );
  }

  #[test]
  fn location_file_append_to() {
    let assert_fn = |result: Config| {
      let result = result.locations.0;
      assert_eq!(result.len(), 2);
      if let (Location::Simple(location1), Location::Simple(location2)) =
        (result.first().unwrap(), result.get(1).unwrap())
      {
        let file1 = location1.backend().as_file().unwrap();
        let file2 = location2.backend().as_file().unwrap();

        return (
          file1.local_path().to_string(),
          location1.to_append().to_string(),
          location1
            .prefix_or_id()
            .unwrap()
            .as_prefix()
            .unwrap()
            .to_string(),
          file2.local_path().to_string(),
          location2.to_append().to_string(),
          location2
            .prefix_or_id()
            .unwrap()
            .as_prefix()
            .unwrap()
            .to_string(),
        );
      }

      panic!();
    };

    test_serialize_and_deserialize(
      r#"
      locations = [ { location = "file://path/dir1", prefix = "prefix1" }, { location = "file://path/dir2", prefix = "prefix2" } ]
      "#,
      (
        "path".to_string(),
        "dir1".to_string(),
        "prefix1".to_string(),
        "path".to_string(),
        "dir2".to_string(),
        "prefix2".to_string(),
      ),
      assert_fn,
    );

    test_serialize_and_deserialize(
      r#"
      locations = [ { location = "file://path/dir1/", prefix = "prefix1" }, { location = "file://path/dir2/", prefix = "prefix2" } ]
      "#,
      (
        "path".to_string(),
        "dir1/".to_string(),
        "prefix1".to_string(),
        "path".to_string(),
        "dir2/".to_string(),
        "prefix2".to_string(),
      ),
      assert_fn,
    );

    test_serialize_and_deserialize(
      r#"
      locations = [ { location = "file://path/", prefix = "prefix1" }, { location = "file://path", prefix = "prefix2" } ]
      "#,
      (
        "path".to_string(),
        "".to_string(),
        "prefix1".to_string(),
        "path".to_string(),
        "".to_string(),
        "prefix2".to_string(),
      ),
      assert_fn,
    );
  }

  #[test]
  fn location_file_id() {
    test_serialize_and_deserialize(
      r#"
      locations = [ { location = "file://path", id = "id1" }, { location = "file://path", id = "id2" } ]
      "#,
      (
        "path".to_string(),
        "id1".to_string(),
        "path".to_string(),
        "id2".to_string(),
      ),
      |result: Config| {
        let result = result.locations.0;
        assert_eq!(result.len(), 2);
        if let (Location::Simple(location1), Location::Simple(location2)) =
          (result.first().unwrap(), result.get(1).unwrap())
        {
          let file1 = location1.backend().as_file().unwrap();
          let file2 = location2.backend().as_file().unwrap();

          return (
            file1.local_path().to_string(),
            location1
              .prefix_or_id()
              .unwrap()
              .as_id()
              .unwrap()
              .to_string(),
            file2.local_path().to_string(),
            location2
              .prefix_or_id()
              .unwrap()
              .as_id()
              .unwrap()
              .to_string(),
          );
        }

        panic!();
      },
    );
  }

  #[test]
  fn location_file_multiple_fail() {
    let config: result::Result<Config, _> = toml::from_str(
      r#"
      locations = [ { location = "file://path", id = "id1", prefix = "prefix1" }]
      "#,
    );
    assert!(config.is_err());
  }

  #[cfg(feature = "aws")]
  #[test]
  fn location_s3() {
    test_serialize_and_deserialize(
      r#"
      locations = [ { location = "s3://bucket", prefix = "prefix1" }, { location = "s3://bucket", prefix = "prefix2" } ]
      "#,
      (
        "bucket".to_string(),
        "prefix1".to_string(),
        "bucket".to_string(),
        "prefix2".to_string(),
      ),
      |result: Config| {
        let result = result.locations.0;
        assert_eq!(result.len(), 2);
        if let (Location::Simple(location1), Location::Simple(location2)) =
          (result.first().unwrap(), result.get(1).unwrap())
          && let (Backend::S3(s31), Backend::S3(s32)) = (location1.backend(), location2.backend())
        {
          return (
            s31.bucket().to_string(),
            location1
              .prefix_or_id()
              .unwrap()
              .as_prefix()
              .unwrap()
              .to_string(),
            s32.bucket().to_string(),
            location2
              .prefix_or_id()
              .unwrap()
              .as_prefix()
              .unwrap()
              .to_string(),
          );
        }

        panic!();
      },
    );
  }

  #[cfg(feature = "url")]
  #[test]
  fn location_url() {
    test_serialize_and_deserialize(
      r#"
      locations = [ { location = "https://example.com", prefix = "prefix1" }, { location = "http://example.com", prefix = "prefix2" } ]
      "#,
      (
        "https://example.com/".to_string(),
        "prefix1".to_string(),
        "http://example.com/".to_string(),
        "prefix2".to_string(),
      ),
      |result: Config| {
        let result = result.locations.0;
        assert_eq!(result.len(), 2);
        if let (Location::Simple(location1), Location::Simple(location2)) =
          (result.first().unwrap(), result.get(1).unwrap())
          && let (Backend::Url(url1), Backend::Url(url2)) =
            (location1.backend(), location2.backend())
        {
          for url in [url1, url2] {
            assert_eq!(url.allow_headers_backend(), &["*".to_string()]);
            assert_eq!(url.allow_headers_client(), &["*".to_string()]);
            assert!(url.deny_headers_backend().is_empty());
            assert!(url.deny_headers_client().is_empty());
          }

          return (
            url1.url().to_string(),
            location1
              .prefix_or_id()
              .unwrap()
              .as_prefix()
              .unwrap()
              .to_string(),
            url2.url().to_string(),
            location2
              .prefix_or_id()
              .unwrap()
              .as_prefix()
              .unwrap()
              .to_string(),
          );
        }

        panic!();
      },
    );
  }

  fn assert_file_location(result: Config) -> (String, String, Option<String>) {
    let result = result.locations.0;
    assert_eq!(result.len(), 1);
    if let Location::Simple(location1) = result.first().unwrap() {
      let file1 = location1.backend().as_file().unwrap();
      return (
        file1.local_path().to_string(),
        location1.to_append().to_string(),
        location1
          .prefix_or_id()
          .and_then(|prefix| prefix.as_prefix().map(|prefix| prefix.to_string())),
      );
    }

    panic!();
  }
}