diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 577d6bed..22e3d34a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,7 +82,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.46.0 + toolchain: 1.57.0 override: true - name: Version features diff --git a/.rustfmt.toml b/.rustfmt.toml deleted file mode 100644 index 1e7954a1..00000000 --- a/.rustfmt.toml +++ /dev/null @@ -1,9 +0,0 @@ -max_width = 80 -hard_tabs = false -tab_spaces = 4 -newline_style = "Unix" -wrap_comments = true -normalize_comments = true -merge_derives = true -force_explicit_abi = true -unstable_features = false diff --git a/examples/windows_guid.rs b/examples/windows_guid.rs index 632f2792..33404b1b 100644 --- a/examples/windows_guid.rs +++ b/examples/windows_guid.rs @@ -20,12 +20,7 @@ fn guid_to_uuid() { Data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], }; - let uuid = Uuid::from_fields( - guid_in.Data1, - guid_in.Data2, - guid_in.Data3, - &guid_in.Data4, - ); + let uuid = Uuid::from_fields(guid_in.Data1, guid_in.Data2, guid_in.Data3, &guid_in.Data4); let guid_out = { let fields = uuid.as_fields(); @@ -66,12 +61,7 @@ fn guid_to_uuid_le_encoded() { Data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], }; - let uuid = Uuid::from_fields_le( - guid_in.Data1, - guid_in.Data2, - guid_in.Data3, - &guid_in.Data4, - ); + let uuid = Uuid::from_fields_le(guid_in.Data1, guid_in.Data2, guid_in.Data3, &guid_in.Data4); let guid_out = { let fields = uuid.to_fields_le(); @@ -107,8 +97,7 @@ fn uuid_from_cocreateguid() { CoCreateGuid(&mut guid as *mut _); } - let uuid = - Uuid::from_fields(guid.Data1, guid.Data2, guid.Data3, &guid.Data4); + let uuid = Uuid::from_fields(guid.Data1, guid.Data2, guid.Data3, &guid.Data4); assert_eq!(Variant::RFC4122, uuid.get_variant()); assert_eq!(Some(Version::Random), uuid.get_version()); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index e7f2eb5d..e1d517b7 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -12,7 +12,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::{quote, quote_spanned}; use std::fmt; -use syn::{LitStr, spanned::Spanned}; +use syn::{spanned::Spanned, LitStr}; mod error; mod parser; @@ -22,32 +22,29 @@ mod parser; pub fn parse_lit(input: TokenStream) -> TokenStream { build_uuid(input.clone()).unwrap_or_else(|e| { let msg = e.to_string(); - let span = - match e { - Error::UuidParse(lit, error::Error(error::ErrorKind::Char { - character, - index, - })) => { - let mut bytes = character as u32; - let mut width = 0; - while bytes != 0 { - bytes >>= 4; - width += 1; - } - let mut s = proc_macro2::Literal::string(""); - s.set_span(lit.span()); - s.subspan(index..index + width - 1) + let span = match e { + Error::UuidParse(lit, error::Error(error::ErrorKind::Char { character, index })) => { + let mut bytes = character as u32; + let mut width = 0; + while bytes != 0 { + bytes >>= 4; + width += 1; } - Error::UuidParse(lit, error::Error( - error::ErrorKind::GroupLength { index, len, .. }, - )) => { - let mut s = proc_macro2::Literal::string(""); - s.set_span(lit.span()); - s.subspan(index..index + len) - } - _ => None, + let mut s = proc_macro2::Literal::string(""); + s.set_span(lit.span()); + s.subspan(index..index + width - 1) + } + Error::UuidParse( + lit, + error::Error(error::ErrorKind::GroupLength { index, len, .. }), + ) => { + let mut s = proc_macro2::Literal::string(""); + s.set_span(lit.span()); + s.subspan(index..index + len) } - .unwrap_or_else(|| TokenStream2::from(input).span()); + _ => None, + } + .unwrap_or_else(|| TokenStream2::from(input).span()); TokenStream::from(quote_spanned! {span=> compile_error!(#msg) @@ -75,8 +72,8 @@ fn build_uuid(input: TokenStream) -> Result { _ => return Err(Error::NonStringLiteral), }; - let bytes = parser::try_parse(&str_lit.value()) - .map_err(|e| Error::UuidParse(str_lit, e.into_err()))?; + let bytes = + parser::try_parse(&str_lit.value()).map_err(|e| Error::UuidParse(str_lit, e.into_err()))?; let tokens = bytes .iter() diff --git a/macros/src/parser.rs b/macros/src/parser.rs index 181bdac1..f6a12b7d 100644 --- a/macros/src/parser.rs +++ b/macros/src/parser.rs @@ -22,10 +22,9 @@ pub const fn try_parse(input: &str) -> Result<[u8; 16], InvalidUuid> { // - `UUID` for a regular hyphenated UUID (36, s) | (38, [b'{', s @ .., b'}']) - | ( - 45, - [b'u', b'r', b'n', b':', b'u', b'u', b'i', b'd', b':', s @ ..], - ) => parse_hyphenated(s), + | (45, [b'u', b'r', b'n', b':', b'u', b'u', b'i', b'd', b':', s @ ..]) => { + parse_hyphenated(s) + } // Any other shaped input is immediately invalid _ => Err(()), }; diff --git a/src/builder.rs b/src/builder.rs index b7faa328..6b2e05c5 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -131,12 +131,7 @@ impl Uuid { /// uuid.hyphenated().to_string(), /// ); /// ``` - pub const fn from_fields_le( - d1: u32, - d2: u16, - d3: u16, - d4: &[u8; 8], - ) -> Uuid { + pub const fn from_fields_le(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Uuid { Uuid::from_bytes([ d1 as u8, (d1 >> 8) as u8, @@ -415,8 +410,8 @@ impl Uuid { /// ``` pub const fn from_bytes_le(b: Bytes) -> Uuid { Uuid([ - b[3], b[2], b[1], b[0], b[5], b[4], b[7], b[6], b[8], b[9], b[10], - b[11], b[12], b[13], b[14], b[15], + b[3], b[2], b[1], b[0], b[5], b[4], b[7], b[6], b[8], b[9], b[10], b[11], b[12], b[13], + b[14], b[15], ]) } @@ -670,12 +665,7 @@ impl Builder { /// "a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8" /// ); /// ``` - pub const fn from_fields_le( - d1: u32, - d2: u16, - d3: u16, - d4: &[u8; 8], - ) -> Self { + pub const fn from_fields_le(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Self { Builder(Uuid::from_fields_le(d1, d2, d3, d4)) } diff --git a/src/external/arbitrary_support.rs b/src/external/arbitrary_support.rs index 7bec2547..cdc177c8 100644 --- a/src/external/arbitrary_support.rs +++ b/src/external/arbitrary_support.rs @@ -21,9 +21,7 @@ mod tests { #[test] fn test_arbitrary() { - let mut bytes = Unstructured::new(&[ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ]); + let mut bytes = Unstructured::new(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); let uuid = Uuid::arbitrary(&mut bytes).unwrap(); diff --git a/src/external/serde_support.rs b/src/external/serde_support.rs index 8a139b87..9c1a7244 100644 --- a/src/external/serde_support.rs +++ b/src/external/serde_support.rs @@ -21,14 +21,9 @@ use serde::{ }; impl Serialize for Uuid { - fn serialize( - &self, - serializer: S, - ) -> Result { + fn serialize(&self, serializer: S) -> Result { if serializer.is_human_readable() { - serializer.serialize_str( - self.hyphenated().encode_lower(&mut Uuid::encode_buffer()), - ) + serializer.serialize_str(self.hyphenated().encode_lower(&mut Uuid::encode_buffer())) } else { serializer.serialize_bytes(self.as_bytes()) } @@ -36,45 +31,31 @@ impl Serialize for Uuid { } impl Serialize for Hyphenated { - fn serialize( - &self, - serializer: S, - ) -> Result { + fn serialize(&self, serializer: S) -> Result { serializer.serialize_str(self.encode_lower(&mut Uuid::encode_buffer())) } } impl Serialize for Simple { - fn serialize( - &self, - serializer: S, - ) -> Result { + fn serialize(&self, serializer: S) -> Result { serializer.serialize_str(self.encode_lower(&mut Uuid::encode_buffer())) } } impl Serialize for Urn { - fn serialize( - &self, - serializer: S, - ) -> Result { + fn serialize(&self, serializer: S) -> Result { serializer.serialize_str(self.encode_lower(&mut Uuid::encode_buffer())) } } impl Serialize for Braced { - fn serialize( - &self, - serializer: S, - ) -> Result { + fn serialize(&self, serializer: S) -> Result { serializer.serialize_str(self.encode_lower(&mut Uuid::encode_buffer())) } } impl<'de> Deserialize<'de> for Uuid { - fn deserialize>( - deserializer: D, - ) -> Result { + fn deserialize>(deserializer: D) -> Result { fn de_error(e: Error) -> E { E::custom(format_args!("UUID parsing failed: {}", e)) } @@ -85,24 +66,15 @@ impl<'de> Deserialize<'de> for Uuid { impl<'vi> de::Visitor<'vi> for UuidVisitor { type Value = Uuid; - fn expecting( - &self, - formatter: &mut fmt::Formatter<'_>, - ) -> fmt::Result { + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { write!(formatter, "a UUID string") } - fn visit_str( - self, - value: &str, - ) -> Result { + fn visit_str(self, value: &str) -> Result { value.parse::().map_err(de_error) } - fn visit_bytes( - self, - value: &[u8], - ) -> Result { + fn visit_bytes(self, value: &[u8]) -> Result { Uuid::from_slice(value).map_err(de_error) } @@ -141,17 +113,11 @@ impl<'de> Deserialize<'de> for Uuid { impl<'vi> de::Visitor<'vi> for UuidBytesVisitor { type Value = Uuid; - fn expecting( - &self, - formatter: &mut fmt::Formatter<'_>, - ) -> fmt::Result { + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { write!(formatter, "bytes") } - fn visit_bytes( - self, - value: &[u8], - ) -> Result { + fn visit_bytes(self, value: &[u8]) -> Result { Uuid::from_slice(value).map_err(de_error) } } @@ -169,10 +135,7 @@ pub mod compact { /// Serialize from a [`Uuid`] as a `[u8; 16]` /// /// [`Uuid`]: ../../struct.Uuid.html - pub fn serialize( - u: &crate::Uuid, - serializer: S, - ) -> Result + pub fn serialize(u: &crate::Uuid, serializer: S) -> Result where S: serde::Serializer, { @@ -292,10 +255,7 @@ mod serde_tests { let uuid_bytes = b"F9168C5E-CEB2-4F"; let u = Uuid::from_slice(uuid_bytes).unwrap(); - serde_test::assert_de_tokens( - &u.readable(), - &[serde_test::Token::Bytes(uuid_bytes)], - ); + serde_test::assert_de_tokens(&u.readable(), &[serde_test::Token::Bytes(uuid_bytes)]); } #[test] diff --git a/src/fmt.rs b/src/fmt.rs index 784fdf39..cd7a112a 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -140,12 +140,10 @@ impl Uuid { } const UPPER: [u8; 16] = [ - b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'A', b'B', - b'C', b'D', b'E', b'F', + b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'A', b'B', b'C', b'D', b'E', b'F', ]; const LOWER: [u8; 16] = [ - b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'a', b'b', - b'c', b'd', b'e', b'f', + b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9', b'a', b'b', b'c', b'd', b'e', b'f', ]; #[inline] @@ -190,11 +188,7 @@ const fn format_hyphenated(src: &[u8; 16], upper: bool) -> [u8; 36] { } #[inline] -fn encode_simple<'b>( - src: &[u8; 16], - buffer: &'b mut [u8], - upper: bool, -) -> &'b mut str { +fn encode_simple<'b>(src: &[u8; 16], buffer: &'b mut [u8], upper: bool) -> &'b mut str { let buf = &mut buffer[..Simple::LENGTH]; let dst = buf.as_mut_ptr(); @@ -207,11 +201,7 @@ fn encode_simple<'b>( } #[inline] -fn encode_hyphenated<'b>( - src: &[u8; 16], - buffer: &'b mut [u8], - upper: bool, -) -> &'b mut str { +fn encode_hyphenated<'b>(src: &[u8; 16], buffer: &'b mut [u8], upper: bool) -> &'b mut str { let buf = &mut buffer[..Hyphenated::LENGTH]; let dst = buf.as_mut_ptr(); @@ -224,11 +214,7 @@ fn encode_hyphenated<'b>( } #[inline] -fn encode_braced<'b>( - src: &[u8; 16], - buffer: &'b mut [u8], - upper: bool, -) -> &'b mut str { +fn encode_braced<'b>(src: &[u8; 16], buffer: &'b mut [u8], upper: bool) -> &'b mut str { let buf = &mut buffer[..Braced::LENGTH]; buf[0] = b'{'; buf[Braced::LENGTH - 1] = b'}'; @@ -244,11 +230,7 @@ fn encode_braced<'b>( } #[inline] -fn encode_urn<'b>( - src: &[u8; 16], - buffer: &'b mut [u8], - upper: bool, -) -> &'b mut str { +fn encode_urn<'b>(src: &[u8; 16], buffer: &'b mut [u8], upper: bool) -> &'b mut str { let buf = &mut buffer[..Urn::LENGTH]; buf[..9].copy_from_slice(b"urn:uuid:"); diff --git a/src/lib.rs b/src/lib.rs index 78b06350..7aee4f78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -402,26 +402,26 @@ pub struct Uuid(Bytes); impl Uuid { /// UUID namespace for Domain Name System (DNS). pub const NAMESPACE_DNS: Self = Uuid([ - 0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, - 0x4f, 0xd4, 0x30, 0xc8, + 0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, + 0xc8, ]); /// UUID namespace for ISO Object Identifiers (OIDs). pub const NAMESPACE_OID: Self = Uuid([ - 0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, - 0x4f, 0xd4, 0x30, 0xc8, + 0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, + 0xc8, ]); /// UUID namespace for Uniform Resource Locators (URLs). pub const NAMESPACE_URL: Self = Uuid([ - 0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, - 0x4f, 0xd4, 0x30, 0xc8, + 0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, + 0xc8, ]); /// UUID namespace for X.500 Distinguished Names (DNs). pub const NAMESPACE_X500: Self = Uuid([ - 0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, - 0x4f, 0xd4, 0x30, 0xc8, + 0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, + 0xc8, ]); /// Returns the variant of the UUID structure. @@ -620,8 +620,7 @@ impl Uuid { let d3 = (self.as_bytes()[6] as u16) | (self.as_bytes()[7] as u16) << 8; - let d4: &[u8; 8] = - convert::TryInto::try_into(&self.as_bytes()[8..16]).unwrap(); + let d4: &[u8; 8] = convert::TryInto::try_into(&self.as_bytes()[8..16]).unwrap(); (d1, d2, d3, d4) } @@ -805,9 +804,9 @@ impl Uuid { /// ``` pub const fn to_bytes_le(&self) -> Bytes { [ - self.0[3], self.0[2], self.0[1], self.0[0], self.0[5], self.0[4], - self.0[7], self.0[6], self.0[8], self.0[9], self.0[10], self.0[11], - self.0[12], self.0[13], self.0[14], self.0[15], + self.0[3], self.0[2], self.0[1], self.0[0], self.0[5], self.0[4], self.0[7], self.0[6], + self.0[8], self.0[9], self.0[10], self.0[11], self.0[12], self.0[13], self.0[14], + self.0[15], ] } @@ -891,15 +890,15 @@ mod tests { pub const fn new() -> Uuid { Uuid::from_bytes([ - 0xF9, 0x16, 0x8C, 0x5E, 0xCE, 0xB2, 0x4F, 0xAA, 0xB6, 0xBF, 0x32, - 0x9B, 0xF3, 0x9F, 0xA1, 0xE4, + 0xF9, 0x16, 0x8C, 0x5E, 0xCE, 0xB2, 0x4F, 0xAA, 0xB6, 0xBF, 0x32, 0x9B, 0xF3, 0x9F, + 0xA1, 0xE4, ]) } pub const fn new2() -> Uuid { Uuid::from_bytes([ - 0xF9, 0x16, 0x8C, 0x5E, 0xCE, 0xB2, 0x4F, 0xAB, 0xB6, 0xBF, 0x32, - 0x9B, 0xF3, 0x9F, 0xA1, 0xE4, + 0xF9, 0x16, 0x8C, 0x5E, 0xCE, 0xB2, 0x4F, 0xAB, 0xB6, 0xBF, 0x32, 0x9B, 0xF3, 0x9F, + 0xA1, 0xE4, ]) } @@ -993,9 +992,8 @@ mod tests { fn test_nil() { let nil = Uuid::nil(); let not_nil = new(); - let from_bytes = Uuid::from_bytes([ - 4, 54, 67, 12, 43, 2, 2, 76, 32, 50, 87, 5, 1, 33, 43, 87, - ]); + let from_bytes = + Uuid::from_bytes([4, 54, 67, 12, 43, 2, 2, 76, 32, 50, 87, 5, 1, 33, 43, 87]); assert_eq!(from_bytes.get_version(), None); @@ -1031,8 +1029,7 @@ mod tests { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_version_v3() { - let uuid = - Uuid::new_v3(&Uuid::NAMESPACE_DNS, "rust-lang.org".as_bytes()); + let uuid = Uuid::new_v3(&Uuid::NAMESPACE_DNS, "rust-lang.org".as_bytes()); assert_eq!(uuid.get_version().unwrap(), Version::Md5); assert_eq!(uuid.get_version_num(), 3); @@ -1042,16 +1039,11 @@ mod tests { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_variant() { let uuid1 = new(); - let uuid2 = - Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap(); - let uuid3 = - Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8").unwrap(); - let uuid4 = - Uuid::parse_str("936DA01F9ABD4d9dC0C702AF85C822A8").unwrap(); - let uuid5 = - Uuid::parse_str("F9168C5E-CEB2-4faa-D6BF-329BF39FA1E4").unwrap(); - let uuid6 = - Uuid::parse_str("f81d4fae-7dec-11d0-7765-00a0c91e6bf6").unwrap(); + let uuid2 = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap(); + let uuid3 = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8").unwrap(); + let uuid4 = Uuid::parse_str("936DA01F9ABD4d9dC0C702AF85C822A8").unwrap(); + let uuid5 = Uuid::parse_str("F9168C5E-CEB2-4faa-D6BF-329BF39FA1E4").unwrap(); + let uuid6 = Uuid::parse_str("f81d4fae-7dec-11d0-7765-00a0c91e6bf6").unwrap(); assert_eq!(uuid1.get_variant(), Variant::RFC4122); assert_eq!(uuid2.get_variant(), Variant::RFC4122); @@ -1350,8 +1342,8 @@ mod tests { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_from_slice() { let b = [ - 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, - 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, + 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, ]; let u = Uuid::from_slice(&b).unwrap(); @@ -1364,8 +1356,8 @@ mod tests { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_from_bytes() { let b = [ - 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, - 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, + 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, ]; let u = Uuid::from_bytes(b); @@ -1391,8 +1383,8 @@ mod tests { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_bytes_roundtrip() { let b_in: crate::Bytes = [ - 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, - 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, + 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, ]; let u = Uuid::from_slice(&b_in).unwrap(); @@ -1406,8 +1398,8 @@ mod tests { #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_bytes_le_roundtrip() { let b = [ - 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, - 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, + 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, ]; let u1 = Uuid::from_bytes(b); diff --git a/src/md5.rs b/src/md5.rs index 3eb21fe8..cb6e7907 100644 --- a/src/md5.rs +++ b/src/md5.rs @@ -1,6 +1,6 @@ #[cfg(feature = "v3")] pub(crate) fn hash(ns: &[u8], src: &[u8]) -> [u8; 16] { - use private_md_5::{Md5, Digest}; + use private_md_5::{Digest, Md5}; let mut hasher = Md5::new(); diff --git a/src/parser.rs b/src/parser.rs index 68d6bbca..ea21d780 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -142,10 +142,9 @@ const fn try_parse(input: &[u8]) -> Result<[u8; 16], InvalidUuid> { // - `UUID` for a regular hyphenated UUID (36, s) | (38, [b'{', s @ .., b'}']) - | ( - 45, - [b'u', b'r', b'n', b':', b'u', b'u', b'i', b'd', b':', s @ ..], - ) => parse_hyphenated(s), + | (45, [b'u', b'r', b'n', b':', b'u', b'u', b'i', b'd', b':', s @ ..]) => { + parse_hyphenated(s) + } // Any other shaped input is immediately invalid _ => Err(()), }; @@ -279,15 +278,10 @@ mod tests { #[test] fn test_parse_uuid_v4_valid() { - let from_hyphenated = - Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8").unwrap(); - let from_simple = - Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8").unwrap(); - let from_urn = - Uuid::parse_str("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8") - .unwrap(); - let from_guid = - Uuid::parse_str("{67e55044-10b1-426f-9247-bb680e5fe0c8}").unwrap(); + let from_hyphenated = Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8").unwrap(); + let from_simple = Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8").unwrap(); + let from_urn = Uuid::parse_str("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8").unwrap(); + let from_guid = Uuid::parse_str("{67e55044-10b1-426f-9247-bb680e5fe0c8}").unwrap(); assert_eq!(from_hyphenated, from_simple); assert_eq!(from_hyphenated, from_urn); @@ -298,13 +292,8 @@ mod tests { assert!(Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").is_ok()); assert!(Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8").is_ok()); assert!(Uuid::parse_str("01020304-1112-2122-3132-414243444546").is_ok()); - assert!(Uuid::parse_str( - "urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8" - ) - .is_ok()); - assert!( - Uuid::parse_str("{6d93bade-bd9f-4e13-8914-9474e1e3567b}").is_ok() - ); + assert!(Uuid::parse_str("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8").is_ok()); + assert!(Uuid::parse_str("{6d93bade-bd9f-4e13-8914-9474e1e3567b}").is_ok()); // Nil let nil = Uuid::nil(); @@ -527,9 +516,6 @@ mod tests { #[test] fn test_try_parse_ascii_non_utf8() { - assert!(Uuid::try_parse_ascii( - b"67e55044-10b1-426f-9247-bb680e5\0e0c8" - ) - .is_err()); + assert!(Uuid::try_parse_ascii(b"67e55044-10b1-426f-9247-bb680e5\0e0c8").is_err()); } } diff --git a/src/v1.rs b/src/v1.rs index c8b425e0..94dd4c71 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -71,15 +71,10 @@ impl Timestamp { /// If uniqueness and monotonicity is required, the user is responsible for /// ensuring that the time value always increases between calls (including /// between restarts of the process and device). - pub fn from_unix( - context: impl ClockSequence, - seconds: u64, - subsec_nanos: u32, - ) -> Self { + pub fn from_unix(context: impl ClockSequence, seconds: u64, subsec_nanos: u32) -> Self { let counter = context.generate_sequence(seconds, subsec_nanos); - let ticks = UUID_TICKS_BETWEEN_EPOCHS - + seconds * 10_000_000 - + u64::from(subsec_nanos) / 100; + let ticks = + UUID_TICKS_BETWEEN_EPOCHS + seconds * 10_000_000 + u64::from(subsec_nanos) / 100; Timestamp { ticks, counter } } @@ -104,8 +99,7 @@ impl Timestamp { pub const fn to_unix(&self) -> (u64, u32) { ( (self.ticks - UUID_TICKS_BETWEEN_EPOCHS) / 10_000_000, - ((self.ticks - UUID_TICKS_BETWEEN_EPOCHS) % 10_000_000) as u32 - * 100, + ((self.ticks - UUID_TICKS_BETWEEN_EPOCHS) % 10_000_000) as u32 * 100, ) } @@ -202,8 +196,7 @@ impl Uuid { pub const fn new_v1(ts: Timestamp, node_id: &[u8; 6]) -> Self { let time_low = (ts.ticks & 0xFFFF_FFFF) as u32; let time_mid = ((ts.ticks >> 32) & 0xFFFF) as u16; - let time_high_and_version = - (((ts.ticks >> 48) & 0x0FFF) as u16) | (1 << 12); + let time_high_and_version = (((ts.ticks >> 48) & 0x0FFF) as u16) | (1 << 12); let mut d4 = [0; 8]; @@ -244,8 +237,8 @@ impl Uuid { | ((self.as_bytes()[2]) as u64) << 8 | (self.as_bytes()[3] as u64); - let counter: u16 = ((self.as_bytes()[8] & 0x3F) as u16) << 8 - | (self.as_bytes()[9] as u16); + let counter: u16 = + ((self.as_bytes()[8] & 0x3F) as u16) << 8 | (self.as_bytes()[9] as u16); Some(Timestamp::from_rfc4122(ticks, counter)) } @@ -316,10 +309,7 @@ mod tests { let node = [1, 2, 3, 4, 5, 6]; let context = Context::new(0); - let uuid = Uuid::new_v1( - Timestamp::from_unix(&context, time, time_fraction), - &node, - ); + let uuid = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node); assert_eq!(uuid.get_version(), Some(Version::Mac)); assert_eq!(uuid.get_variant(), Variant::RFC4122); @@ -333,8 +323,7 @@ mod tests { assert_eq!(ts.0 - 0x01B2_1DD2_1381_4000, 14_968_545_358_129_460); // Ensure parsing the same UUID produces the same timestamp - let parsed = - Uuid::parse_str("20616934-4ba2-11e7-8000-010203040506").unwrap(); + let parsed = Uuid::parse_str("20616934-4ba2-11e7-8000-010203040506").unwrap(); assert_eq!( uuid.get_timestamp().unwrap(), @@ -352,31 +341,19 @@ mod tests { // This context will wrap let context = Context::new((u16::MAX >> 2) - 1); - let uuid1 = Uuid::new_v1( - Timestamp::from_unix(&context, time, time_fraction), - &node, - ); + let uuid1 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node); let time: u64 = 1_496_854_536; - let uuid2 = Uuid::new_v1( - Timestamp::from_unix(&context, time, time_fraction), - &node, - ); + let uuid2 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node); assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16382); assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 0); let time = 1_496_854_535; - let uuid3 = Uuid::new_v1( - Timestamp::from_unix(&context, time, time_fraction), - &node, - ); - let uuid4 = Uuid::new_v1( - Timestamp::from_unix(&context, time, time_fraction), - &node, - ); + let uuid3 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node); + let uuid4 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node); assert_eq!(uuid3.get_timestamp().unwrap().to_rfc4122().1, 1); assert_eq!(uuid4.get_timestamp().unwrap().to_rfc4122().1, 2); diff --git a/src/v3.rs b/src/v3.rs index 94f83769..bfe9d597 100644 --- a/src/v3.rs +++ b/src/v3.rs @@ -41,10 +41,7 @@ mod tests { #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; - use crate::{ - Variant, Version, - std::string::ToString, - }; + use crate::{std::string::ToString, Variant, Version}; static FIXTURE: &'static [(&'static Uuid, &'static str, &'static str)] = &[ ( diff --git a/src/v5.rs b/src/v5.rs index c91b0a1d..0edbc685 100644 --- a/src/v5.rs +++ b/src/v5.rs @@ -40,10 +40,7 @@ mod tests { #[cfg(target_arch = "wasm32")] use wasm_bindgen_test::*; - use crate::{ - Variant, Version, - std::string::ToString, - }; + use crate::{std::string::ToString, Variant, Version}; static FIXTURE: &'static [(&'static Uuid, &'static str, &'static str)] = &[ ( @@ -131,8 +128,7 @@ mod tests { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn test_get_version() { - let uuid = - Uuid::new_v5(&Uuid::NAMESPACE_DNS, "rust-lang.org".as_bytes()); + let uuid = Uuid::new_v5(&Uuid::NAMESPACE_DNS, "rust-lang.org".as_bytes()); assert_eq!(uuid.get_version(), Some(Version::Sha1)); assert_eq!(uuid.get_version_num(), 5);