google-search 0.1.1

Open default browser to Google search results for a given query string.
Documentation
pub fn add(left: u64, right: u64) -> u64 {
    left + right
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = add(2, 2);
        assert_eq!(result, 4);
    }
}

use std::borrow::Cow;

/// Open default browser to Google search results for the given query string.
/// Returns Ok(()) if the browser launch command succeeded.
pub fn search(query: impl AsRef<str>) -> Result<(), String> {
    let q = query.as_ref();
    if q.trim().is_empty() {
        return Err("query must not be empty".to_string());
    }
    let encoded: Cow<str> = urlencoding::encode(q);
    let url = format!("https://www.google.com/search?q={}", encoded);
    webbrowser::open(&url).map_err(|e| format!("failed to open browser: {}", e))
}