-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathquery.rs
29 lines (25 loc) · 822 Bytes
/
query.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/// Simple struct that is supposed to serve as a utility for inputs.
#[derive(Debug, Clone)]
pub struct Query(String, String);
impl Query {
/// Parses a string into Query
pub fn from_str(query: &str) -> Query {
let query_parts = query.split_once(' ').unwrap_or((query, ""));
Query(query_parts.0.to_string(), query_parts.1.to_string())
}
/// Get the prefix of a query, for example
/// "something test", the prefix is "something"
pub fn prefix(&self) -> &str {
&self.0
}
/// Get the rest of the query (arguments, etc.)
///
/// For example, "something test", the query is "test"
pub fn query(&self) -> &str {
&self.1
}
/// If you do not want to listen to a prefix then you can just read the entire query
pub fn all(&self) -> String {
format!("{} {}", self.0, self.1)
}
}