<commit_before>#[derive(Debug, Clone)]
pub struct RequestURI {
    base: String,
    query: String,
}

impl RequestURI {
    /// Create RequestURI type resource.
    pub fn new(base: String, query: String) -> RequestURI {
        RequestURI {
            base: base,
            query: query,
        }
    }

    /// Construct requesting URL from RequestURI type resource.
    ///
    /// # Examples
    ///
    /// ```
    /// use ruroonga_client;
    /// use ruroonga_client::builtin::command_query::CommandQuery;
    /// let uri_base = ruroonga_client::URIBase::new().build();
    /// let mut command = CommandQuery::new("select");
    /// command.set_argument(vec![("table", "Sites")]);
    /// let url = ruroonga_client::RequestURI::new(uri_base, command.encode()).url();
    /// ```
    pub fn url(self) -> String {
        let url = format!("{}{}", self.base, self.query);
        url
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use builtin::command_query::CommandQuery;
    use uri_base::URIBase;

    #[test]
    fn construct_request_uri() {
        let url = RequestURI::new("http://localhost:10041".to_string(),
                                  "/d/status".to_string())
            .url();
        assert_eq!("http://localhost:10041/d/status", url)
    }

    #[test]
    fn construct_with_actual_usage() {
        let uri_base = URIBase::new().build();
        let mut command = CommandQuery::new("select");
        command.set_argument(vec![("table", "Sites")]);
        let url = RequestURI::new(uri_base, command.encode()).url();
        assert_eq!("http://localhost:10041/d/select?table=Sites", url)
    }
}
<commit_msg>request_uri: Use Cow to reduce allocation<commit_after>use std::borrow::Cow;

#[derive(Debug, Clone)]
pub struct RequestURI<'a> {
    base: Cow<'a, str>,
    query: Cow<'a, str>,
}

impl<'a> RequestURI<'a> {
    /// Create RequestURI type resource.
    pub fn new<T>(base: T, query: T) -> RequestURI<'a>
        where T: Into<Cow<'a, str>>
    {
        RequestURI {
            base: base.into(),
            query: query.into(),
        }
    }

    /// Construct requesting URL from RequestURI type resource.
    ///
    /// # Examples
    ///
    /// ```
    /// use ruroonga_client;
    /// use ruroonga_client::builtin::command_query::CommandQuery;
    /// let uri_base = ruroonga_client::URIBase::new().build();
    /// let mut command = CommandQuery::new("select");
    /// command.set_argument(vec![("table", "Sites")]);
    /// let url = ruroonga_client::RequestURI::new(uri_base, command.encode()).url();
    /// ```
    pub fn url(self) -> String {
        let url = format!("{}{}", self.base.into_owned(), self.query.into_owned());
        url
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use builtin::command_query::CommandQuery;
    use uri_base::URIBase;

    #[test]
    fn construct_request_uri() {
        let url = RequestURI::new("http://localhost:10041",
                                  "/d/status")
            .url();
        assert_eq!("http://localhost:10041/d/status", url)
    }

    #[test]
    fn construct_request_uri_with_owned_str() {
        let url = RequestURI::new("http://localhost:10041".to_string(),
                                  "/d/status".to_string())
            .url();
        assert_eq!("http://localhost:10041/d/status", url)
    }

    #[test]
    fn construct_with_actual_usage() {
        let uri_base = URIBase::new().build();
        let mut command = CommandQuery::new("select");
        command.set_argument(vec![("table", "Sites")]);
        let url = RequestURI::new(uri_base, command.encode()).url();
        assert_eq!("http://localhost:10041/d/select?table=Sites", url)
    }
}

{'fraction_non_alphanumeric': 0.17759784075573548, 'fraction_numerical': 0.010796221322537112, 'mean_word_length': 2.3813868613138687, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2532959', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1177, 'n_words': 221}