Documented from_param and made the example runnable

This commit is contained in:
Lori Holden 2017-01-13 20:06:15 -05:00
parent 1919ab8317
commit 655864658c
1 changed files with 8 additions and 2 deletions

View File

@ -16,7 +16,7 @@ pub use self::uuid_ext::ParseError as UuidParseError;
/// To use, add the `uuid` feature to the `rocket_contrib` dependencies section /// To use, add the `uuid` feature to the `rocket_contrib` dependencies section
/// of your `Cargo.toml`: /// of your `Cargo.toml`:
/// ///
/// ```toml,ignore /// ```toml
/// [dependencies.rocket_contrib] /// [dependencies.rocket_contrib]
/// version = "*" /// version = "*"
/// default-features = false /// default-features = false
@ -39,14 +39,18 @@ impl UUID {
/// Consumes the UUID wrapper returning the underlying Uuid type. /// Consumes the UUID wrapper returning the underlying Uuid type.
/// ///
/// # Example /// # Example
/// ```rust,ignore /// ```rust
/// # extern crate rocket_contrib;
/// # extern crate uuid;
/// # use rocket_contrib::UUID; /// # use rocket_contrib::UUID;
/// # use std::str::FromStr; /// # use std::str::FromStr;
/// # use uuid::Uuid; /// # use uuid::Uuid;
/// # fn main() {
/// let uuid_str = "c1aa1e3b-9614-4895-9ebd-705255fa5bc2"; /// let uuid_str = "c1aa1e3b-9614-4895-9ebd-705255fa5bc2";
/// let real_uuid = Uuid::from_str(uuid_str).unwrap(); /// let real_uuid = Uuid::from_str(uuid_str).unwrap();
/// let my_inner_uuid = UUID::from_str(uuid_str).unwrap().into_inner(); /// let my_inner_uuid = UUID::from_str(uuid_str).unwrap().into_inner();
/// assert_eq!(real_uuid, my_inner_uuid); /// assert_eq!(real_uuid, my_inner_uuid);
/// # }
/// ``` /// ```
#[inline(always)] #[inline(always)]
pub fn into_inner(self) -> uuid_ext::Uuid { pub fn into_inner(self) -> uuid_ext::Uuid {
@ -64,6 +68,8 @@ impl fmt::Display for UUID {
impl<'a> FromParam<'a> for UUID { impl<'a> FromParam<'a> for UUID {
type Error = UuidParseError; type Error = UuidParseError;
/// A value is successfully parsed if the `str` is a properly formatted
/// UUID, otherwise `UuidParseError` is returned.
fn from_param(p: &'a str) -> Result<UUID, Self::Error> { fn from_param(p: &'a str) -> Result<UUID, Self::Error> {
p.parse() p.parse()
} }