/// TemplateVar represents the value of a template variable, which can be a /// scalar (a simple string), a list of strings, or an associative array of /// strings. /// /// Normally, it is not necessary to use this class unless you are implementing /// the `IntoTemplateVar` trait for your own classes. #[derive(Clone)] pubenum TemplateVar { /// A simple string such as `"foo"`
Scalar(String), /// A list of strings such as `["foo", "bar"]`
List(Vec<String>), /// An associative array of strings, such as /// `[("key1", "value1"), ("key2", "value2")]`
AssociativeArray(Vec<(String, String)>),
}
/// IntoTemplateVar represents any type that can be converted into a TemplateVar /// for use as the value of a template variable, such as a `String`, /// `Vec<String>`, or `Vec<(String, String)>`. Default implementations are /// available for those three types, as well as the `&str` versions. /// /// Example /// ------- /// Here is an example of implementing `IntoTemplateVar` for your own `Address` /// struct. Note that you should probably implement the trait for a reference to /// your struct, not the actual struct, unless you intend to move the value /// efficiently. /// /// ```ignore /// struct Address { /// city: String, /// state: String /// } /// /// impl <'a> IntoTemplateVar for &'a Address { /// fn into_template_var(self) -> TemplateVar { /// TemplateVar::AssociativeArray(vec![ /// ("city".to_string(), self.city.clone()), /// ("state".to_string(), self.state.clone()) /// ]) /// } /// } /// ``` /// /// Now, `Address` variables can be set as `UriTemplate` variables. /// /// ```ignore /// let address = Address { /// city: "Los Angelos".to_string(), /// state: "California".to_string() /// }; /// /// let uri = UriTemplate::new("http://example.com/view{?address*}") /// .set("address", &address) /// .build(); /// /// assert_eq!( /// uri, /// "http://example.com/view?city=Los%20Angelos&state=California" /// ); /// ``` pubtrait IntoTemplateVar { fn into_template_var(self) -> TemplateVar;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.