-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
96 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use std::hash::Hash; | ||
use std::ops::Deref; | ||
use std::rc::Rc; | ||
|
||
use crate::Tok; | ||
|
||
#[derive(Clone, Debug, Eq)] | ||
pub enum OrcString { | ||
Interned(Tok<String>), | ||
Runtime(Rc<String>), | ||
} | ||
|
||
impl OrcString { | ||
pub fn get_string(&self) -> String { | ||
self.as_str().to_owned() | ||
} | ||
} | ||
|
||
impl Deref for OrcString { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
match self { | ||
Self::Interned(t) => t, | ||
Self::Runtime(r) => r, | ||
} | ||
} | ||
} | ||
|
||
impl Hash for OrcString { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
self.as_str().hash(state) | ||
} | ||
} | ||
|
||
impl From<String> for OrcString { | ||
fn from(value: String) -> Self { | ||
Self::Runtime(Rc::new(value)) | ||
} | ||
} | ||
|
||
impl From<Tok<String>> for OrcString { | ||
fn from(value: Tok<String>) -> Self { | ||
Self::Interned(value) | ||
} | ||
} | ||
|
||
impl PartialEq for OrcString { | ||
fn eq(&self, other: &Self) -> bool { | ||
match (self, other) { | ||
(Self::Interned(t1), Self::Interned(t2)) => t1 == t2, | ||
_ => **self == **other, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters