ReprTree: add from_char()

This commit is contained in:
Michael Sippel 2023-03-25 08:49:19 +01:00
parent 17b58e6bca
commit 1575fa756e
Signed by: senvas
GPG key ID: 060F22F65102F95C

View file

@ -1,7 +1,7 @@
use { use {
r3vi::view::{AnyOuterViewPort, OuterViewPort, View}, r3vi::view::{AnyOuterViewPort, OuterViewPort, View},
crate::{ crate::{
type_system::{TypeTerm} type_system::{TypeTerm, Context}
}, },
std::{ std::{
collections::HashMap, collections::HashMap,
@ -31,6 +31,14 @@ impl ReprTree {
&self.type_tag &self.type_tag
} }
pub fn from_char(ctx: &Arc<RwLock<Context>>, c: char) -> Arc<RwLock<Self>> {
let buf = r3vi::buffer::singleton::SingletonBuffer::<char>::new(c);
ReprTree::new_leaf(
(ctx, "( Char )"),
buf.get_port().into()
)
}
pub fn new_leaf(type_tag: impl Into<TypeTerm>, port: AnyOuterViewPort) -> Arc<RwLock<Self>> { pub fn new_leaf(type_tag: impl Into<TypeTerm>, port: AnyOuterViewPort) -> Arc<RwLock<Self>> {
let mut tree = ReprTree::new(type_tag.into()); let mut tree = ReprTree::new(type_tag.into());
tree.insert_leaf(vec![].into_iter(), port); tree.insert_leaf(vec![].into_iter(), port);