-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
variable: Add DummyVariable to make unvariable expression easy to make
- Loading branch information
1 parent
90cc812
commit f80b3fe
Showing
9 changed files
with
78 additions
and
46 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use stack::Stack; | ||
use expression::Expression; | ||
use variable::DummyVariable; | ||
|
||
mod float; | ||
mod integer; | ||
|
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,26 @@ | ||
use std::fmt; | ||
use convert_ref::TryFromRef; | ||
|
||
/// Struct that implement [`TryFromRef`] and always returns `Err`, | ||
/// used to fake variables when don't needed in expressions. | ||
/// | ||
/// Prefer using this type with the [`DummyVariables`] fake container. | ||
/// | ||
/// [`TryFromRef`]: ../convert_ref/trait.TryFromRef.html | ||
/// [`DummyVariables`]: ../variable/struct.DummyVariables.html | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct DummyVariable; | ||
|
||
impl<T> TryFromRef<T> for DummyVariable { | ||
type Err = (); | ||
|
||
fn try_from_ref(_: &T) -> Result<Self, Self::Err> { | ||
Err(()) | ||
} | ||
} | ||
|
||
impl fmt::Display for DummyVariable { | ||
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { | ||
Err(fmt::Error) | ||
} | ||
} |
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,24 @@ | ||
use std::ops::Index; | ||
use std::marker::PhantomData; | ||
|
||
/// Struct that implement [`Index`], | ||
/// used to fake variables when don't needed in expressions. | ||
/// | ||
/// Prefer using this container with the [`DummyVariable`] fake type. | ||
/// | ||
/// # Panics | ||
/// Panics if you call the [`index()`] method. | ||
/// | ||
/// [`Index`]: https://doc.rust-lang.org/std/ops/trait.Index.html | ||
/// [`DummyVariable`]: ../variable/struct.DummyVariable.html | ||
/// [`index()`]: https://doc.rust-lang.org/std/ops/trait.Index.html#tymethod.index | ||
#[derive(Debug, Copy, Clone)] | ||
pub struct DummyVariables<T>(PhantomData<T>); | ||
|
||
impl<I, T> Index<I> for DummyVariables<T> { | ||
type Output = T; | ||
|
||
fn index(&self, _: I) -> &Self::Output { | ||
panic!("DummyVariables cannot return variable!") | ||
} | ||
} |
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,5 @@ | ||
mod dummy_variables; | ||
mod dummy_variable; | ||
|
||
pub use self::dummy_variables::DummyVariables; | ||
pub use self::dummy_variable::DummyVariable; |