mirror of
https://github.com/RGBCube/cstree
synced 2025-07-27 09:07:44 +00:00
derive impl Display
for NodeOrToken
This commit is contained in:
parent
c47b430135
commit
d8ce241cf5
3 changed files with 29 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
/// Convenience type to represent tree elements which may either be a node or a token.
|
/// Convenience type to represent tree elements which may either be a node or a token.
|
||||||
///
|
///
|
||||||
/// Used for both red and green tree, references to elements, ...
|
/// Used for both red and green tree, references to elements, ...
|
||||||
|
@ -53,6 +55,15 @@ impl<N: Clone, T: Clone> NodeOrToken<&N, &T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<N: fmt::Display, T: fmt::Display> fmt::Display for NodeOrToken<N, T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
NodeOrToken::Node(node) => node.fmt(f),
|
||||||
|
NodeOrToken::Token(token) => token.fmt(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
Next,
|
Next,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
use common::{build_recursive, build_tree_with_cache, Element, SyntaxNode};
|
use common::{
|
||||||
|
build_recursive, build_tree_with_cache, Element, SyntaxElement, SyntaxElementRef, SyntaxNode, SyntaxToken,
|
||||||
|
};
|
||||||
use cstree::{GreenNodeBuilder, NodeCache, SyntaxKind, TextRange};
|
use cstree::{GreenNodeBuilder, NodeCache, SyntaxKind, TextRange};
|
||||||
use lasso::{Resolver, Rodeo};
|
use lasso::{Resolver, Rodeo};
|
||||||
|
|
||||||
|
@ -129,3 +131,15 @@ fn inline_resolver() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn assert_debug_display() {
|
||||||
|
use std::fmt;
|
||||||
|
fn f<T: fmt::Debug + fmt::Display>() {}
|
||||||
|
|
||||||
|
f::<SyntaxNode<(), lasso::Rodeo>>();
|
||||||
|
f::<SyntaxToken<(), lasso::Rodeo>>();
|
||||||
|
f::<SyntaxElement<(), lasso::Rodeo>>();
|
||||||
|
f::<SyntaxElementRef<'static, (), lasso::Rodeo>>();
|
||||||
|
f::<cstree::NodeOrToken<String, u128>>();
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ use cstree::{GreenNode, GreenNodeBuilder, Language, NodeCache, SyntaxKind};
|
||||||
use lasso::Interner;
|
use lasso::Interner;
|
||||||
|
|
||||||
pub type SyntaxNode<D = (), R = ()> = cstree::SyntaxNode<TestLang, D, R>;
|
pub type SyntaxNode<D = (), R = ()> = cstree::SyntaxNode<TestLang, D, R>;
|
||||||
|
pub type SyntaxToken<D = (), R = ()> = cstree::SyntaxToken<TestLang, D, R>;
|
||||||
|
pub type SyntaxElement<D = (), R = ()> = cstree::SyntaxElement<TestLang, D, R>;
|
||||||
|
pub type SyntaxElementRef<'a, D = (), R = ()> = cstree::SyntaxElementRef<'a, TestLang, D, R>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Element<'s> {
|
pub enum Element<'s> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue