Checkpoint
This commit is contained in:
47
src/util/pretty.rs
Normal file
47
src/util/pretty.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
use internment::ArcIntern;
|
||||
use pretty::{DocAllocator, Pretty};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PrettySymbol {
|
||||
name: ArcIntern<String>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ArcIntern<String>> for PrettySymbol {
|
||||
fn from(value: &'a ArcIntern<String>) -> Self {
|
||||
PrettySymbol { name: value.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, D, A> Pretty<'a, D, A> for PrettySymbol
|
||||
where
|
||||
A: 'a,
|
||||
D: ?Sized + DocAllocator<'a, A>,
|
||||
{
|
||||
fn pretty(self, allocator: &'a D) -> pretty::DocBuilder<'a, D, A> {
|
||||
allocator.text(self.name.as_ref().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, D, A> Pretty<'a, D, A> for &'b PrettySymbol
|
||||
where
|
||||
A: 'a,
|
||||
D: ?Sized + DocAllocator<'a, A>,
|
||||
{
|
||||
fn pretty(self, allocator: &'a D) -> pretty::DocBuilder<'a, D, A> {
|
||||
allocator.text(self.name.as_ref().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::ptr_arg)]
|
||||
pub fn pretty_comma_separated<'a, D, A, P>(
|
||||
allocator: &'a D,
|
||||
args: &Vec<P>,
|
||||
) -> pretty::DocBuilder<'a, D, A>
|
||||
where
|
||||
A: 'a,
|
||||
D: ?Sized + DocAllocator<'a, A>,
|
||||
P: Pretty<'a, D, A> + Clone,
|
||||
{
|
||||
let individuals = args.iter().map(|x| x.clone().pretty(allocator));
|
||||
allocator.intersperse(individuals, ", ")
|
||||
}
|
||||
@@ -5,6 +5,12 @@ pub struct ScopedMap<K: Eq + Hash + PartialEq, V> {
|
||||
scopes: Vec<HashMap<K, V>>,
|
||||
}
|
||||
|
||||
impl<K: Eq + Hash + PartialEq, V> Default for ScopedMap<K, V> {
|
||||
fn default() -> Self {
|
||||
ScopedMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Eq + Hash + PartialEq, V> ScopedMap<K, V> {
|
||||
/// Generate a new scoped map.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user