virtual_node/event/
event_name.rs1use std::borrow::Cow;
2
3#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
7pub struct EventName(Cow<'static, str>);
8
9impl EventName {
10 pub fn new(name: Cow<'static, str>) -> Self {
16 EventName(name)
17 }
18
19 pub fn with_on_prefix(&self) -> &str {
21 &self.0.as_ref()
22 }
23
24 pub fn without_on_prefix(&self) -> &str {
26 &self.0.as_ref()[2..]
27 }
28}
29
30impl EventName {
31 pub fn is_delegated(&self) -> bool {
34 if self == &Self::ONCLICK {
35 true
36 } else {
37 false
38 }
39 }
40}
41
42impl EventName {
43 pub const ONCLICK: EventName = EventName(Cow::Borrowed("onclick"));
45
46 pub const ONINPUT: EventName = EventName(Cow::Borrowed("oninput"));
48}
49
50impl From<&'static str> for EventName {
51 fn from(event_name: &'static str) -> Self {
52 EventName(Cow::Borrowed(event_name))
53 }
54}
55
56impl From<String> for EventName {
57 fn from(event_name: String) -> Self {
58 EventName(Cow::Owned(event_name))
59 }
60}