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 {
r3vi::view::{AnyOuterViewPort, OuterViewPort, View},
crate::{
type_system::{TypeTerm}
type_system::{TypeTerm, Context}
},
std::{
collections::HashMap,
@ -31,6 +31,14 @@ impl ReprTree {
&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>> {
let mut tree = ReprTree::new(type_tag.into());
tree.insert_leaf(vec![].into_iter(), port);