maudit_rolldown_rstr/
lib.rs

1//! `Rstr`:
2//! - is meant to be a bundler-specialized string type for rolldown.
3//! - to smooth integration with `oxc`'s string types.
4
5use std::{fmt::Display, ops::Deref};
6
7/// `OxcStr` is a alias of string type oxc used internally.
8pub type OxcStr = oxc::span::CompactStr;
9
10mod to_str;
11pub use to_str::ToRstr;
12
13#[derive(Debug, Clone, Hash, PartialEq, Eq)]
14pub struct Rstr(OxcStr);
15
16impl PartialOrd for Rstr {
17  fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
18    Some(self.as_str().cmp(other.as_str()))
19  }
20}
21
22impl Ord for Rstr {
23  fn cmp(&self, other: &Self) -> std::cmp::Ordering {
24    self.as_str().cmp(other.as_str())
25  }
26}
27
28impl Rstr {
29  pub fn new(s: &str) -> Self {
30    Self(OxcStr::new(s))
31  }
32
33  pub fn inner(&self) -> &OxcStr {
34    &self.0
35  }
36
37  pub fn as_str(&self) -> &str {
38    self.0.as_str()
39  }
40}
41
42impl Default for Rstr {
43  fn default() -> Self {
44    Self(OxcStr::new(""))
45  }
46}
47
48impl Deref for Rstr {
49  type Target = str;
50
51  fn deref(&self) -> &Self::Target {
52    self.as_str()
53  }
54}
55
56impl AsRef<str> for Rstr {
57  fn as_ref(&self) -> &str {
58    self.0.as_str()
59  }
60}
61
62impl Display for Rstr {
63  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64    self.as_str().fmt(f)
65  }
66}