formatting changes

This commit is contained in:
Tilen Pintarič 2022-07-11 21:11:15 +02:00
parent 7188b00a9e
commit 18560d4ad2
4 changed files with 40 additions and 36 deletions

View File

@ -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,34 @@ 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)
}
.unwrap_or_else(|| TokenStream2::from(input).span());
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,
}
.unwrap_or_else(|| TokenStream2::from(input).span());
TokenStream::from(quote_spanned! {span=>
compile_error!(#msg)

View File

@ -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();

View File

@ -30,7 +30,11 @@ impl Uuid {
/// [`NAMESPACE_URL`]: #associatedconstant.NAMESPACE_URL
/// [`NAMESPACE_X500`]: #associatedconstant.NAMESPACE_X500
pub fn new_v3(namespace: &Uuid, name: &[u8]) -> Uuid {
crate::Builder::from_md5_bytes(crate::md5::hash(namespace.as_bytes(), name)).into_uuid()
crate::Builder::from_md5_bytes(crate::md5::hash(
namespace.as_bytes(),
name,
))
.into_uuid()
}
}
@ -41,10 +45,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)] = &[
(

View File

@ -29,7 +29,11 @@ impl Uuid {
/// [`NAMESPACE_URL`]: struct.Uuid.html#associatedconst.NAMESPACE_URL
/// [`NAMESPACE_X500`]: struct.Uuid.html#associatedconst.NAMESPACE_X500
pub fn new_v5(namespace: &Uuid, name: &[u8]) -> Uuid {
crate::Builder::from_sha1_bytes(crate::sha1::hash(namespace.as_bytes(), name)).into_uuid()
crate::Builder::from_sha1_bytes(crate::sha1::hash(
namespace.as_bytes(),
name,
))
.into_uuid()
}
}
@ -40,10 +44,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)] = &[
(