-
Notifications
You must be signed in to change notification settings - Fork 9
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
29 changed files
with
164 additions
and
151 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
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
File renamed without changes.
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,4 @@ | ||
#![deny(rust_2018_idioms)] | ||
#![deny(clippy::all)] | ||
pub mod node; | ||
pub mod syntax; |
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,47 @@ | ||
use indexmap::IndexMap; | ||
use std::hash::Hash; | ||
|
||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub type NodeMap<T> = IndexMap<NodeId, T>; | ||
|
||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub struct NodeId(pub u32); | ||
|
||
/// Auto-incrementing [`NodeIdGenerator`] | ||
pub struct AutoNodeIdGenerator { | ||
next_id: NodeId, | ||
} | ||
|
||
impl Default for AutoNodeIdGenerator { | ||
fn default() -> Self { | ||
AutoNodeIdGenerator { next_id: NodeId(1) } | ||
} | ||
} | ||
|
||
/// A provider of 'fresh' [`NodeId`]s. | ||
pub trait NodeIdGenerator { | ||
/// Provides a 'fresh' [`NodeId`]. | ||
fn id(&mut self) -> NodeId; | ||
} | ||
|
||
impl NodeIdGenerator for AutoNodeIdGenerator { | ||
#[inline] | ||
fn id(&mut self) -> NodeId { | ||
let mut next = NodeId(&self.next_id.0 + 1); | ||
std::mem::swap(&mut self.next_id, &mut next); | ||
next | ||
} | ||
} | ||
|
||
/// A provider of [`NodeId`]s that are always `0`; Useful for testing | ||
#[derive(Default)] | ||
pub struct NullIdGenerator {} | ||
|
||
impl NodeIdGenerator for NullIdGenerator { | ||
fn id(&mut self) -> NodeId { | ||
NodeId(0) | ||
} | ||
} |
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
Oops, something went wrong.