-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
c3d7b8a
commit d98a901
Showing
6 changed files
with
76 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,6 @@ pub use constraint::*; | |
|
||
mod map; | ||
pub use map::*; | ||
|
||
mod tuple; | ||
pub use tuple::*; |
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::{ops::Deref, sync::Arc}; | ||
|
||
use super::Constant; | ||
|
||
/// A Tuple: a [Constant] | ||
#[derive(Debug, Eq, PartialEq, Clone, PartialOrd, Ord)] | ||
pub struct Tuple { | ||
values: Arc<[Constant]>, | ||
} | ||
|
||
impl Default for Tuple { | ||
fn default() -> Self { | ||
Self { | ||
values: [].into_iter().collect(), | ||
} | ||
} | ||
} | ||
|
||
impl Tuple { | ||
/// Returns the size of the tuple. | ||
pub fn arity(&self) -> usize { | ||
self.values.len() | ||
} | ||
} | ||
|
||
impl Deref for Tuple { | ||
type Target = [Constant]; | ||
|
||
fn deref(&self) -> &[Constant] { | ||
&self.values | ||
} | ||
} | ||
|
||
impl FromIterator<Constant> for Tuple { | ||
fn from_iter<T: IntoIterator<Item = Constant>>(iter: T) -> Self { | ||
Self { | ||
values: iter.into_iter().collect(), | ||
} | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Tuple { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "(")?; | ||
f.write_str( | ||
&self | ||
.iter() | ||
.map(|x| ToString::to_string(x)) | ||
.by_ref() | ||
.intersperse(", ".into()) | ||
.collect::<String>(), | ||
)?; | ||
write!(f, ")") | ||
} | ||
} |
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