preserves/implementations/rust/oo/src/lib.rs

76 lines
2.2 KiB
Rust
Raw Normal View History

2022-11-03 16:17:31 +00:00
pub mod boundary;
pub mod domain;
pub mod error;
2022-10-31 20:21:28 +00:00
pub mod float;
2022-11-03 16:17:31 +00:00
pub mod reader;
pub mod repr;
2022-10-31 20:21:28 +00:00
pub mod signed_integer;
2022-11-03 16:17:31 +00:00
pub mod source;
pub mod types;
pub mod writer;
2022-11-03 16:48:44 +00:00
pub use domain::*;
2022-11-03 16:17:31 +00:00
pub use reader::Reader;
pub use repr::Annotations;
pub use repr::Atom;
pub use repr::Bytes;
pub use repr::Embedded;
pub use repr::IOValue;
pub use repr::Map;
pub use repr::NoValue;
pub use repr::Record;
pub use repr::Set;
pub use repr::Symbol;
pub use repr::Value;
pub use repr::owned;
pub use repr::value;
2022-10-31 20:21:28 +00:00
pub use signed_integer::SignedInteger;
2022-11-03 16:48:44 +00:00
pub use source::BinarySource;
pub use source::BytesBinarySource;
pub use source::IOBinarySource;
2022-11-03 16:17:31 +00:00
pub use types::AtomClass;
pub use types::CompoundClass;
pub use types::ValueClass;
pub use writer::Writer;
2022-10-31 20:21:28 +00:00
#[cfg(test)]
mod demo {
use crate::*;
2022-11-02 12:34:39 +00:00
fn getit<'a>(d: &'a dyn Value<NoValue>, k: &str) -> Option<&'a dyn Value<NoValue>> {
2022-11-02 15:26:21 +00:00
d.get(&k)
2022-11-02 12:34:39 +00:00
}
2022-10-31 20:21:28 +00:00
#[test] fn a() {
2022-11-03 16:17:31 +00:00
let l = Symbol::new("label");
2022-11-02 16:03:38 +00:00
let r = Record::new(owned::<NoValue, _>(l.clone()), vec![owned(1), owned(2), owned(3)]);
let r2 = Record::new(owned::<NoValue, _>(l), vec![owned(1), owned(2), owned(4)]);
2022-10-31 20:21:28 +00:00
let mut v: Map<Box<dyn Value<NoValue>>, String> = Map::new();
v.insert(Box::new("abc"), "def".to_owned());
v.insert(Box::new(123), "xyz".to_owned());
v.insert(Box::new(vec![1, 2, 3]), "www".to_owned());
2022-11-02 16:03:38 +00:00
v.insert(Box::new(r2), "bbb".to_owned());
v.insert(Box::new(r), "aaa".to_owned());
2022-10-31 20:21:28 +00:00
let w: &dyn Value<NoValue> = &v;
println!("GETw abc {:?}", w.get(&"abc"));
println!("GETw 123 {:?}", w.get(&123));
println!("GETw qqq {:?}", w.get(&"qqq"));
println!("GETv abc {:?}", v.get(value(&"abc")));
println!("GETv 123 {:?}", v.get(value(&123)));
println!("GETv qqq {:?}", v.get(value(&"qqq")));
2022-11-02 16:03:38 +00:00
for (kk, vv) in w.entries() {
2022-10-31 20:21:28 +00:00
println!("{:?} {:?} ==> {:?} {:?}", kk.value_class(), kk, vv.value_class(), vv);
}
2022-11-02 12:34:39 +00:00
// {
// use std::io::BufRead;
// for line in std::io::stdin().lock().lines() {
// let line = line.unwrap();
// let val = w.get(&line);
2022-11-02 15:26:21 +00:00
// println!("{:?} ==> {:?} == {:?}", line, val, getit(&v, &line));
2022-11-02 12:34:39 +00:00
// }
// }
2022-10-31 20:21:28 +00:00
}
}