use std::rc::Rc;
use zamm_yin::concepts::{Archetype, FormTrait};
use zamm_yin::graph::value_wrappers::KBValue;
use zamm_yin::graph::value_wrappers::StrongValue;
use zamm_yin::node_wrappers::BaseNodeTrait;
#[allow(clippy::redundant_allocation)]
pub trait Documentable {
fn set_documentation(&mut self, doc: &str);
fn documentation(&self) -> Option<Rc<Box<dyn KBValue>>>;
}
impl Documentable for Archetype {
fn set_documentation(&mut self, doc: &str) {
set_documentation(self, doc)
}
fn documentation(&self) -> Option<Rc<Box<dyn KBValue>>> {
self.essence().value()
}
}
pub fn set_documentation(form: &mut dyn FormTrait, doc: &str) {
form.essence_mut()
.set_value(Box::new(StrongValue::new(doc.to_string())));
}
#[cfg(test)]
mod tests {
use super::*;
use crate::concepts::{initialize_kb, Implement};
use zamm_yin::concepts::ArchetypeTrait;
use zamm_yin::graph::value_wrappers::unwrap_strong;
#[test]
fn test_archetype_documentation() {
initialize_kb();
Implement::archetype().set_documentation("This implements stuff.");
assert_eq!(
unwrap_strong(&Implement::archetype().documentation()),
Some(&"This implements stuff.".to_string())
);
}
}