@@ -11,16 +11,25 @@ fn map_prefix<'p, I: Into<Prefix<'p>>>(prefix: I) -> Result<Prefix<'p>, Error> {
1111 return Err ( Error :: PrefixTooLong ( prefix. inner . len ( ) ) ) ;
1212 }
1313
14- for b in prefix. inner . as_bytes ( ) {
14+ if prefix. inner . is_empty ( ) {
15+ return Err ( Error :: PrefixExpected ) ;
16+ }
17+
18+ let underscore = b'_' ;
19+ let bytes = prefix. inner . as_bytes ( ) ;
20+
21+ if * bytes. first ( ) . unwrap ( ) == underscore || * bytes. last ( ) . unwrap ( ) == underscore {
22+ return Err ( Error :: IncorrectPrefixCharacter ( underscore as char ) ) ;
23+ }
24+
25+ for b in bytes {
1526 if cfg ! ( feature = "delimited" ) && * b == b'_' {
1627 continue ;
1728 } else if !b. is_ascii_lowercase ( ) {
1829 return Err ( Error :: IncorrectPrefixCharacter ( * b as char ) ) ;
1930 }
2031 }
21- if prefix. inner . is_empty ( ) {
22- return Err ( Error :: PrefixExpected ) ;
23- }
32+
2433 Ok ( prefix)
2534}
2635
@@ -322,7 +331,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
322331 }
323332 }
324333
325- #[ cfg( all ( uuid_unstable , feature = "uuid-v6" ) ) ]
334+ #[ cfg( feature = "uuid-v6" ) ]
326335 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v6" ) ) ) ]
327336 /// Create a new UUID-backed ID by generating a v6 UUID with a prefix
328337 ///
@@ -338,7 +347,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
338347 } )
339348 }
340349
341- #[ cfg( all ( uuid_unstable , feature = "uuid-v6" ) ) ]
350+ #[ cfg( feature = "uuid-v6" ) ]
342351 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v6" ) ) ) ]
343352 /// Create a new UUID-backed ID by generating a v6 UUID without a prefix
344353 ///
@@ -350,7 +359,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
350359 }
351360 }
352361
353- #[ cfg( all ( uuid_unstable , feature = "uuid-v6" ) ) ]
362+ #[ cfg( feature = "uuid-v6" ) ]
354363 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v6" ) ) ) ]
355364 /// Create a new UUID-backed ID by generating a v6 UUID with a prefix
356365 ///
@@ -362,7 +371,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
362371 } )
363372 }
364373
365- #[ cfg( all ( uuid_unstable , feature = "uuid-v6" ) ) ]
374+ #[ cfg( feature = "uuid-v6" ) ]
366375 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v6" ) ) ) ]
367376 /// Create a new UUID-backed ID by generating a v6 UUID without a prefix
368377 ///
@@ -374,7 +383,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
374383 }
375384 }
376385
377- #[ cfg( all ( uuid_unstable , feature = "uuid-v7" ) ) ]
386+ #[ cfg( feature = "uuid-v7" ) ]
378387 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v7" ) ) ) ]
379388 /// Create a new UUID-backed ID by generating a v7 UUID with a prefix
380389 ///
@@ -386,7 +395,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
386395 } )
387396 }
388397
389- #[ cfg( all ( uuid_unstable , feature = "uuid-v7" ) ) ]
398+ #[ cfg( feature = "uuid-v7" ) ]
390399 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v7" ) ) ) ]
391400 /// Create a new UUID-backed ID by generating a v7 UUID without a prefix
392401 ///
@@ -398,7 +407,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
398407 }
399408 }
400409
401- #[ cfg( all ( uuid_unstable , feature = "uuid-v7" ) ) ]
410+ #[ cfg( feature = "uuid-v7" ) ]
402411 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v7" ) ) ) ]
403412 /// Create a new UUID-backed ID by generating a v7 UUID with a prefix
404413 ///
@@ -410,7 +419,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
410419 } )
411420 }
412421
413- #[ cfg( all ( uuid_unstable , feature = "uuid-v7" ) ) ]
422+ #[ cfg( feature = "uuid-v7" ) ]
414423 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v7" ) ) ) ]
415424 /// Create a new UUID-backed ID by generating a v7 UUID without a prefix
416425 ///
@@ -422,7 +431,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
422431 }
423432 }
424433
425- #[ cfg( all ( uuid_unstable , feature = "uuid-v8" ) ) ]
434+ #[ cfg( feature = "uuid-v8" ) ]
426435 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v8" ) ) ) ]
427436 /// Create a new UUID-backed ID by generating a v7 UUID with a prefix
428437 ///
@@ -434,7 +443,7 @@ impl<'p> DynamicStrongId<'p, Uuid> {
434443 } )
435444 }
436445
437- #[ cfg( all ( uuid_unstable , feature = "uuid-v8" ) ) ]
446+ #[ cfg( feature = "uuid-v8" ) ]
438447 #[ cfg_attr( docsrs, doc( cfg( feature = "uuid-v8" ) ) ) ]
439448 /// Create a new UUID-backed ID by generating a v7 UUID without a prefix
440449 ///
0 commit comments