mirror of
https://github.com/uuid-rs/uuid.git
synced 2025-10-03 07:44:56 +00:00
formatting changes
This commit is contained in:
parent
7188b00a9e
commit
18560d4ad2
@ -12,7 +12,7 @@ use proc_macro::TokenStream;
|
|||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::{quote, quote_spanned};
|
use quote::{quote, quote_spanned};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use syn::{LitStr, spanned::Spanned};
|
use syn::{spanned::Spanned, LitStr};
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
mod parser;
|
mod parser;
|
||||||
@ -22,32 +22,34 @@ mod parser;
|
|||||||
pub fn parse_lit(input: TokenStream) -> TokenStream {
|
pub fn parse_lit(input: TokenStream) -> TokenStream {
|
||||||
build_uuid(input.clone()).unwrap_or_else(|e| {
|
build_uuid(input.clone()).unwrap_or_else(|e| {
|
||||||
let msg = e.to_string();
|
let msg = e.to_string();
|
||||||
let span =
|
let span = match e {
|
||||||
match e {
|
Error::UuidParse(
|
||||||
Error::UuidParse(lit, error::Error(error::ErrorKind::Char {
|
lit,
|
||||||
character,
|
error::Error(error::ErrorKind::Char { character, index }),
|
||||||
index,
|
) => {
|
||||||
})) => {
|
let mut bytes = character as u32;
|
||||||
let mut bytes = character as u32;
|
let mut width = 0;
|
||||||
let mut width = 0;
|
while bytes != 0 {
|
||||||
while bytes != 0 {
|
bytes >>= 4;
|
||||||
bytes >>= 4;
|
width += 1;
|
||||||
width += 1;
|
|
||||||
}
|
|
||||||
let mut s = proc_macro2::Literal::string("");
|
|
||||||
s.set_span(lit.span());
|
|
||||||
s.subspan(index..index + width - 1)
|
|
||||||
}
|
}
|
||||||
Error::UuidParse(lit, error::Error(
|
let mut s = proc_macro2::Literal::string("");
|
||||||
error::ErrorKind::GroupLength { index, len, .. },
|
s.set_span(lit.span());
|
||||||
)) => {
|
s.subspan(index..index + width - 1)
|
||||||
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());
|
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=>
|
TokenStream::from(quote_spanned! {span=>
|
||||||
compile_error!(#msg)
|
compile_error!(#msg)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#[cfg(feature = "v3")]
|
#[cfg(feature = "v3")]
|
||||||
pub(crate) fn hash(ns: &[u8], src: &[u8]) -> [u8; 16] {
|
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();
|
let mut hasher = Md5::new();
|
||||||
|
|
||||||
|
11
src/v3.rs
11
src/v3.rs
@ -30,7 +30,11 @@ impl Uuid {
|
|||||||
/// [`NAMESPACE_URL`]: #associatedconstant.NAMESPACE_URL
|
/// [`NAMESPACE_URL`]: #associatedconstant.NAMESPACE_URL
|
||||||
/// [`NAMESPACE_X500`]: #associatedconstant.NAMESPACE_X500
|
/// [`NAMESPACE_X500`]: #associatedconstant.NAMESPACE_X500
|
||||||
pub fn new_v3(namespace: &Uuid, name: &[u8]) -> Uuid {
|
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")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{std::string::ToString, Variant, Version};
|
||||||
Variant, Version,
|
|
||||||
std::string::ToString,
|
|
||||||
};
|
|
||||||
|
|
||||||
static FIXTURE: &'static [(&'static Uuid, &'static str, &'static str)] = &[
|
static FIXTURE: &'static [(&'static Uuid, &'static str, &'static str)] = &[
|
||||||
(
|
(
|
||||||
|
11
src/v5.rs
11
src/v5.rs
@ -29,7 +29,11 @@ impl Uuid {
|
|||||||
/// [`NAMESPACE_URL`]: struct.Uuid.html#associatedconst.NAMESPACE_URL
|
/// [`NAMESPACE_URL`]: struct.Uuid.html#associatedconst.NAMESPACE_URL
|
||||||
/// [`NAMESPACE_X500`]: struct.Uuid.html#associatedconst.NAMESPACE_X500
|
/// [`NAMESPACE_X500`]: struct.Uuid.html#associatedconst.NAMESPACE_X500
|
||||||
pub fn new_v5(namespace: &Uuid, name: &[u8]) -> Uuid {
|
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")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{std::string::ToString, Variant, Version};
|
||||||
Variant, Version,
|
|
||||||
std::string::ToString,
|
|
||||||
};
|
|
||||||
|
|
||||||
static FIXTURE: &'static [(&'static Uuid, &'static str, &'static str)] = &[
|
static FIXTURE: &'static [(&'static Uuid, &'static str, &'static str)] = &[
|
||||||
(
|
(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user