web_sys_ec/
by.rs

1pub(crate) mod inner {
2    pub enum By {
3        Id(String),
4        Class(String),
5        TagName(String),
6        QuerySelector(String),
7    }
8
9    impl core::fmt::Display for By {
10        fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
11            match self {
12                By::Id(id) => write!(f, "HTML element with id '{}' (`{:?}`)", id, &self),
13                By::Class(class) => {
14                    write!(f, "HTML element with class '{}' (`{:?}`)", class, &self)
15                }
16                By::TagName(tag_name) => write!(
17                    f,
18                    "HTML element with tag name '{}' (`{:?}`)",
19                    tag_name, &self
20                ),
21                By::QuerySelector(selector) => write!(
22                    f,
23                    "HTML element queried with selector '{}' (`{:?}`)",
24                    selector, &self
25                ),
26            }
27        }
28    }
29
30    impl core::fmt::Debug for By {
31        fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
32            match self {
33                By::Id(id) => write!(f, "By::Id({id:?})"),
34                By::Class(class) => write!(f, "By::Class({class:?})"),
35                By::TagName(tag_name) => write!(f, "By::TagName({tag_name:?})"),
36                By::QuerySelector(selector) => write!(f, "By::QuerySelector({selector:?})"),
37            }
38        }
39    }
40}
41
42#[allow(non_snake_case)]
43pub mod By {
44    use super::inner;
45
46    #[inline]
47    pub fn Id(id: impl Into<String>) -> inner::By {
48        inner::By::Id(id.into())
49    }
50
51    #[inline]
52    pub fn Class(class: impl Into<String>) -> inner::By {
53        inner::By::Class(class.into())
54    }
55
56    #[inline]
57    pub fn TagName(tag_name: impl Into<String>) -> inner::By {
58        inner::By::TagName(tag_name.into())
59    }
60
61    #[inline]
62    pub fn QuerySelector(selector: impl Into<String>) -> inner::By {
63        inner::By::QuerySelector(selector.into())
64    }
65}