AppFlowy/frontend/rust-lib/build-tool/flowy-ast/src/symbol.rs

79 lines
2.5 KiB
Rust
Raw Normal View History

use std::fmt::{self, Display};
use syn::{Ident, Path};
#[derive(Copy, Clone)]
pub struct Symbol(&'static str);
2022-12-03 04:03:52 +00:00
// Protobuf
pub const PB_ATTRS: Symbol = Symbol("pb");
2022-12-03 04:03:52 +00:00
//#[pb(skip)]
pub const SKIP: Symbol = Symbol("skip");
//#[pb(index = "1")]
pub const PB_INDEX: Symbol = Symbol("index");
//#[pb(one_of)]
pub const PB_ONE_OF: Symbol = Symbol("one_of");
//#[pb(skip_pb_deserializing = "...")]
pub const SKIP_PB_DESERIALIZING: Symbol = Symbol("skip_pb_deserializing");
//#[pb(skip_pb_serializing)]
pub const SKIP_PB_SERIALIZING: Symbol = Symbol("skip_pb_serializing");
//#[pb(serialize_pb_with = "...")]
pub const SERIALIZE_PB_WITH: Symbol = Symbol("serialize_pb_with");
//#[pb(deserialize_pb_with = "...")]
pub const DESERIALIZE_PB_WITH: Symbol = Symbol("deserialize_pb_with");
//#[pb(struct="some struct")]
pub const PB_STRUCT: Symbol = Symbol("struct");
//#[pb(enum="some enum")]
pub const PB_ENUM: Symbol = Symbol("enum");
2022-12-03 04:03:52 +00:00
// Event
2021-07-07 06:14:37 +00:00
pub const EVENT_INPUT: Symbol = Symbol("input");
pub const EVENT_OUTPUT: Symbol = Symbol("output");
pub const EVENT_IGNORE: Symbol = Symbol("ignore");
pub const EVENT: Symbol = Symbol("event");
pub const EVENT_ERR: Symbol = Symbol("event_err");
2021-07-07 06:14:37 +00:00
2022-12-03 04:03:52 +00:00
// Node
pub const NODE_ATTRS: Symbol = Symbol("node");
2022-12-03 13:12:45 +00:00
pub const NODES_ATTRS: Symbol = Symbol("nodes");
pub const NODE_TYPE: Symbol = Symbol("node_type");
pub const NODE_INDEX: Symbol = Symbol("index");
2022-12-04 01:54:25 +00:00
pub const RENAME_NODE: Symbol = Symbol("rename");
pub const CHILD_NODE_NAME: Symbol = Symbol("child_name");
pub const CHILD_NODE_INDEX: Symbol = Symbol("child_index");
2022-12-03 04:03:52 +00:00
pub const SKIP_NODE_ATTRS: Symbol = Symbol("skip_node_attribute");
pub const GET_NODE_VALUE_WITH: Symbol = Symbol("get_value_with");
pub const SET_NODE_VALUE_WITH: Symbol = Symbol("set_value_with");
2022-12-03 13:12:45 +00:00
pub const GET_VEC_ELEMENT_WITH: Symbol = Symbol("get_element_with");
pub const GET_MUT_VEC_ELEMENT_WITH: Symbol = Symbol("get_mut_element_with");
2022-12-04 07:23:24 +00:00
pub const WITH_CHILDREN: Symbol = Symbol("with_children");
2022-12-03 04:03:52 +00:00
impl PartialEq<Symbol> for Ident {
fn eq(&self, word: &Symbol) -> bool {
self == word.0
}
}
impl<'a> PartialEq<Symbol> for &'a Ident {
fn eq(&self, word: &Symbol) -> bool {
*self == word.0
}
}
impl PartialEq<Symbol> for Path {
fn eq(&self, word: &Symbol) -> bool {
self.is_ident(word.0)
}
}
impl<'a> PartialEq<Symbol> for &'a Path {
fn eq(&self, word: &Symbol) -> bool {
self.is_ident(word.0)
}
}
impl Display for Symbol {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.0)
}
}