diff --git a/README.md b/README.md index 662da21..7041fad 100644 --- a/README.md +++ b/README.md @@ -147,13 +147,18 @@ assert_eq!(length, 5.0 * kilometers); // This only holds in SI units! ``` The combination of `value_unchecked` and `new_unchecked` comes in handy when using third party libraries that only takes the raw storage type as argument. As an example, suppose we have a function `foo` that takes a `Vec` and returns a `Vec`, and suppose it sorts the numbers or does some other unit safe operation. Then we could reasonably write: ```rust -let lengths: Vec> = vec![1.0 * meters, 2.0 * kilometers, 3.0 * meters, 4.0 * kilometers]; -let unchecked = lengths - .into_iter() - .map(|x| x.value_unchecked()) - .collect(); -let fooed = foo(unchecked); -let result: Vec<_> = fooed.into_iter().map(|x| Length::new_unchecked(x)).collect(); + let lengths: Vec> = vec![ + 1.0 * meters, + 2.0 * kilometers, + 3.0 * meters, + 4.0 * kilometers, + ]; + let unchecked = lengths.into_iter().map(|x| x.value_unchecked()).collect(); + let fooed = foo(unchecked); + let result: Vec<_> = fooed + .into_iter() + .map(|x| Length::new_unchecked(x)) + .collect(); ``` ## Debug `Debug` is implemented and will print the quantity in its base representation. diff --git a/src/lib.rs b/src/lib.rs index 59de385..5b4db95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -183,13 +183,18 @@ //! # fn foo(x: Vec) -> Vec { //! # x //! # } -//! let lengths: Vec> = vec![1.0 * meters, 2.0 * kilometers, 3.0 * meters, 4.0 * kilometers]; -//! let unchecked = lengths -//! .into_iter() -//! .map(|x| x.value_unchecked()) -//! .collect(); -//! let fooed = foo(unchecked); -//! let result: Vec<_> = fooed.into_iter().map(|x| Length::new_unchecked(x)).collect(); +//! let lengths: Vec> = vec![ +//! 1.0 * meters, +//! 2.0 * kilometers, +//! 3.0 * meters, +//! 4.0 * kilometers, +//! ]; +//! let unchecked = lengths.into_iter().map(|x| x.value_unchecked()).collect(); +//! let fooed = foo(unchecked); +//! let result: Vec<_> = fooed +//! .into_iter() +//! .map(|x| Length::new_unchecked(x)) +//! .collect(); //! ``` //! ## Debug //! `Debug` is implemented and will print the quantity in its base representation.