use super::{super::data::*, vertex_finder::*};
use {
depiction::*,
std::{collections::*, io},
};
#[derive(Clone, Debug)]
pub enum VertexSelector {
VertexID(ID),
Finder(VertexFinder),
}
impl VertexSelector {
pub fn new_vertex(vertex_id: ID) -> Self {
Self::VertexID(vertex_id)
}
pub fn new_finder(finder: Call) -> Self {
Self::Finder(VertexFinder::new(finder))
}
}
impl Depict for VertexSelector {
fn depict<WriteT>(&self, writer: &mut WriteT, context: &DepictionContext) -> io::Result<()>
where
WriteT: io::Write,
{
match self {
Self::VertexID(id) => id.depict(writer, context),
Self::Finder(vertex_filter) => vertex_filter.depict(writer, context),
}
}
}
impl Into<Expression> for VertexSelector {
fn into(self) -> Expression {
let mut map = BTreeMap::default();
match self {
Self::VertexID(id) => {
map.insert("id".into(), id.kind.as_str().into());
}
Self::Finder(vertex_finder) => {
map.insert("finder".into(), vertex_finder.into());
}
}
Expression::Map(map)
}
}