floria/entities/
vertex_selector.rs1use super::{super::data::*, vertex_finder::*};
2
3use {
4 kutil::cli::depict::*,
5 std::{collections::*, io},
6};
7
8#[derive(Clone, Debug)]
14pub enum VertexSelector {
15 VertexID(ID),
17
18 Finder(VertexFinder),
20}
21
22impl VertexSelector {
23 pub fn new_vertex(vertex_id: ID) -> Self {
25 Self::VertexID(vertex_id)
26 }
27
28 pub fn new_finder(finder: Call) -> Self {
30 Self::Finder(VertexFinder::new(finder))
31 }
32}
33
34impl Depict for VertexSelector {
35 fn depict<WriteT>(&self, writer: &mut WriteT, context: &DepictionContext) -> io::Result<()>
36 where
37 WriteT: io::Write,
38 {
39 match self {
40 Self::VertexID(id) => id.depict(writer, context),
41 Self::Finder(vertex_filter) => vertex_filter.depict(writer, context),
42 }
43 }
44}
45
46impl Into<Expression> for VertexSelector {
47 fn into(self) -> Expression {
48 let mut map = BTreeMap::default();
49
50 match self {
51 Self::VertexID(id) => {
52 map.insert("id".into(), id.kind.as_str().into());
53 }
54
55 Self::Finder(vertex_finder) => {
56 map.insert("finder".into(), vertex_finder.into());
57 }
58 }
59
60 Expression::Map(map)
61 }
62}