google_search/
lib.rs

1pub fn add(left: u64, right: u64) -> u64 {
2    left + right
3}
4
5#[cfg(test)]
6mod tests {
7    use super::*;
8
9    #[test]
10    fn it_works() {
11        let result = add(2, 2);
12        assert_eq!(result, 4);
13    }
14}
15
16use std::borrow::Cow;
17
18/// Open default browser to Google search results for the given query string.
19/// Returns Ok(()) if the browser launch command succeeded.
20pub fn search(query: impl AsRef<str>) -> Result<(), String> {
21    let q = query.as_ref();
22    if q.trim().is_empty() {
23        return Err("query must not be empty".to_string());
24    }
25    let encoded: Cow<str> = urlencoding::encode(q);
26    let url = format!("https://www.google.com/search?q={}", encoded);
27    webbrowser::open(&url).map_err(|e| format!("failed to open browser: {}", e))
28}