summaryrefslogtreecommitdiffstats
path: root/src/bindgen/ir/path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindgen/ir/path.rs')
-rw-r--r--src/bindgen/ir/path.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/bindgen/ir/path.rs b/src/bindgen/ir/path.rs
new file mode 100644
index 0000000..480c31b
--- /dev/null
+++ b/src/bindgen/ir/path.rs
@@ -0,0 +1,50 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use std::cmp::Ordering;
+use std::fmt;
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct Path {
+ name: String,
+}
+
+impl Path {
+ pub fn new<T>(name: T) -> Self
+ where
+ String: From<T>,
+ {
+ Self { name: name.into() }
+ }
+
+ pub fn name(&self) -> &str {
+ &self.name
+ }
+
+ pub fn replace_self_with(&mut self, path: &Self) -> bool {
+ if self.name() != "Self" {
+ return false;
+ }
+ *self = path.clone();
+ true
+ }
+}
+
+impl PartialOrd for Path {
+ fn partial_cmp(&self, other: &Path) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for Path {
+ fn cmp(&self, other: &Path) -> Ordering {
+ self.name.cmp(&other.name)
+ }
+}
+
+impl fmt::Display for Path {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{}", self.name)
+ }
+}