Skip to content

Commit a22d2bd

Browse files
committed
STYLE: format src
1 parent b2f4d5c commit a22d2bd

File tree

7 files changed

+263
-214
lines changed

7 files changed

+263
-214
lines changed

src/array_string.rs

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ use std::str;
1111
use std::str::FromStr;
1212
use std::str::Utf8Error;
1313

14-
use crate::CapacityError;
15-
use crate::LenUint;
1614
use crate::char::encode_utf8;
1715
use crate::utils::MakeMaybeUninit;
16+
use crate::CapacityError;
17+
use crate::LenUint;
1818

19-
#[cfg(feature="serde")]
20-
use serde::{Serialize, Deserialize, Serializer, Deserializer};
21-
19+
#[cfg(feature = "serde")]
20+
use serde::{Deserialize, Deserializer, Serialize, Serializer};
2221

2322
/// A string with a fixed capacity.
2423
///
@@ -37,16 +36,14 @@ pub struct ArrayString<const CAP: usize> {
3736
len: LenUint,
3837
}
3938

40-
impl<const CAP: usize> Default for ArrayString<CAP>
41-
{
39+
impl<const CAP: usize> Default for ArrayString<CAP> {
4240
/// Return an empty `ArrayString`
4341
fn default() -> ArrayString<CAP> {
4442
ArrayString::new()
4543
}
4644
}
4745

48-
impl<const CAP: usize> ArrayString<CAP>
49-
{
46+
impl<const CAP: usize> ArrayString<CAP> {
5047
/// Create a new empty `ArrayString`.
5148
///
5249
/// Capacity is inferred from the type parameter.
@@ -62,7 +59,10 @@ impl<const CAP: usize> ArrayString<CAP>
6259
pub fn new() -> ArrayString<CAP> {
6360
assert_capacity_limit!(CAP);
6461
unsafe {
65-
ArrayString { xs: MaybeUninit::uninit().assume_init(), len: 0 }
62+
ArrayString {
63+
xs: MaybeUninit::uninit().assume_init(),
64+
len: 0,
65+
}
6666
}
6767
}
6868

@@ -77,16 +77,23 @@ impl<const CAP: usize> ArrayString<CAP>
7777
/// ```
7878
pub const fn new_const() -> ArrayString<CAP> {
7979
assert_capacity_limit_const!(CAP);
80-
ArrayString { xs: MakeMaybeUninit::ARRAY, len: 0 }
80+
ArrayString {
81+
xs: MakeMaybeUninit::ARRAY,
82+
len: 0,
83+
}
8184
}
8285

8386
/// Return the length of the string.
8487
#[inline]
85-
pub const fn len(&self) -> usize { self.len as usize }
88+
pub const fn len(&self) -> usize {
89+
self.len as usize
90+
}
8691

8792
/// Returns whether the string is empty.
8893
#[inline]
89-
pub const fn is_empty(&self) -> bool { self.len() == 0 }
94+
pub const fn is_empty(&self) -> bool {
95+
self.len() == 0
96+
}
9097

9198
/// Create a new `ArrayString` from a `str`.
9299
///
@@ -146,7 +153,7 @@ impl<const CAP: usize> ArrayString<CAP>
146153
unsafe {
147154
ArrayString {
148155
xs: MaybeUninit::zeroed().assume_init(),
149-
len: CAP as _
156+
len: CAP as _,
150157
}
151158
}
152159
}
@@ -160,7 +167,9 @@ impl<const CAP: usize> ArrayString<CAP>
160167
/// assert_eq!(string.capacity(), 3);
161168
/// ```
162169
#[inline(always)]
163-
pub const fn capacity(&self) -> usize { CAP }
170+
pub const fn capacity(&self) -> usize {
171+
CAP
172+
}
164173

165174
/// Return if the `ArrayString` is completely filled.
166175
///
@@ -172,7 +181,9 @@ impl<const CAP: usize> ArrayString<CAP>
172181
/// string.push_str("A");
173182
/// assert!(string.is_full());
174183
/// ```
175-
pub const fn is_full(&self) -> bool { self.len() == self.capacity() }
184+
pub const fn is_full(&self) -> bool {
185+
self.len() == self.capacity()
186+
}
176187

177188
/// Returns the capacity left in the `ArrayString`.
178189
///
@@ -296,7 +307,7 @@ impl<const CAP: usize> ArrayString<CAP>
296307
///
297308
/// ```
298309
/// use arrayvec::ArrayString;
299-
///
310+
///
300311
/// let mut s = ArrayString::<3>::from("foo").unwrap();
301312
///
302313
/// assert_eq!(s.pop(), Some('o'));
@@ -336,7 +347,7 @@ impl<const CAP: usize> ArrayString<CAP>
336347
pub fn truncate(&mut self, new_len: usize) {
337348
if new_len <= self.len() {
338349
assert!(self.is_char_boundary(new_len));
339-
unsafe {
350+
unsafe {
340351
// In libstd truncate is called on the underlying vector,
341352
// which in turns drops each element.
342353
// As we know we don't have to worry about Drop,
@@ -356,7 +367,7 @@ impl<const CAP: usize> ArrayString<CAP>
356367
///
357368
/// ```
358369
/// use arrayvec::ArrayString;
359-
///
370+
///
360371
/// let mut s = ArrayString::<3>::from("foo").unwrap();
361372
///
362373
/// assert_eq!(s.remove(0), 'f');
@@ -372,9 +383,11 @@ impl<const CAP: usize> ArrayString<CAP>
372383
let next = idx + ch.len_utf8();
373384
let len = self.len();
374385
unsafe {
375-
ptr::copy(self.as_ptr().add(next),
376-
self.as_mut_ptr().add(idx),
377-
len - next);
386+
ptr::copy(
387+
self.as_ptr().add(next),
388+
self.as_mut_ptr().add(idx),
389+
len - next,
390+
);
378391
self.set_len(len - (next - idx));
379392
}
380393
ch
@@ -419,8 +432,7 @@ impl<const CAP: usize> ArrayString<CAP>
419432
}
420433
}
421434

422-
impl<const CAP: usize> Deref for ArrayString<CAP>
423-
{
435+
impl<const CAP: usize> Deref for ArrayString<CAP> {
424436
type Target = str;
425437
#[inline]
426438
fn deref(&self) -> &str {
@@ -431,8 +443,7 @@ impl<const CAP: usize> Deref for ArrayString<CAP>
431443
}
432444
}
433445

434-
impl<const CAP: usize> DerefMut for ArrayString<CAP>
435-
{
446+
impl<const CAP: usize> DerefMut for ArrayString<CAP> {
436447
#[inline]
437448
fn deref_mut(&mut self) -> &mut str {
438449
unsafe {
@@ -443,60 +454,58 @@ impl<const CAP: usize> DerefMut for ArrayString<CAP>
443454
}
444455
}
445456

446-
impl<const CAP: usize> PartialEq for ArrayString<CAP>
447-
{
457+
impl<const CAP: usize> PartialEq for ArrayString<CAP> {
448458
fn eq(&self, rhs: &Self) -> bool {
449459
**self == **rhs
450460
}
451461
}
452462

453-
impl<const CAP: usize> PartialEq<str> for ArrayString<CAP>
454-
{
463+
impl<const CAP: usize> PartialEq<str> for ArrayString<CAP> {
455464
fn eq(&self, rhs: &str) -> bool {
456465
&**self == rhs
457466
}
458467
}
459468

460-
impl<const CAP: usize> PartialEq<ArrayString<CAP>> for str
461-
{
469+
impl<const CAP: usize> PartialEq<ArrayString<CAP>> for str {
462470
fn eq(&self, rhs: &ArrayString<CAP>) -> bool {
463471
self == &**rhs
464472
}
465473
}
466474

467-
impl<const CAP: usize> Eq for ArrayString<CAP>
468-
{ }
475+
impl<const CAP: usize> Eq for ArrayString<CAP> {}
469476

470-
impl<const CAP: usize> Hash for ArrayString<CAP>
471-
{
477+
impl<const CAP: usize> Hash for ArrayString<CAP> {
472478
fn hash<H: Hasher>(&self, h: &mut H) {
473479
(**self).hash(h)
474480
}
475481
}
476482

477-
impl<const CAP: usize> Borrow<str> for ArrayString<CAP>
478-
{
479-
fn borrow(&self) -> &str { self }
483+
impl<const CAP: usize> Borrow<str> for ArrayString<CAP> {
484+
fn borrow(&self) -> &str {
485+
self
486+
}
480487
}
481488

482-
impl<const CAP: usize> AsRef<str> for ArrayString<CAP>
483-
{
484-
fn as_ref(&self) -> &str { self }
489+
impl<const CAP: usize> AsRef<str> for ArrayString<CAP> {
490+
fn as_ref(&self) -> &str {
491+
self
492+
}
485493
}
486494

487-
impl<const CAP: usize> fmt::Debug for ArrayString<CAP>
488-
{
489-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
495+
impl<const CAP: usize> fmt::Debug for ArrayString<CAP> {
496+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
497+
(**self).fmt(f)
498+
}
490499
}
491500

492-
impl<const CAP: usize> fmt::Display for ArrayString<CAP>
493-
{
494-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
501+
impl<const CAP: usize> fmt::Display for ArrayString<CAP> {
502+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
503+
(**self).fmt(f)
504+
}
495505
}
496506

497507
/// `Write` appends written data to the end of the string.
498-
impl<const CAP: usize> fmt::Write for ArrayString<CAP>
499-
{
508+
impl<const CAP: usize> fmt::Write for ArrayString<CAP> {
500509
fn write_char(&mut self, c: char) -> fmt::Result {
501510
self.try_push(c).map_err(|_| fmt::Error)
502511
}
@@ -506,8 +515,7 @@ impl<const CAP: usize> fmt::Write for ArrayString<CAP>
506515
}
507516
}
508517

509-
impl<const CAP: usize> Clone for ArrayString<CAP>
510-
{
518+
impl<const CAP: usize> Clone for ArrayString<CAP> {
511519
fn clone(&self) -> ArrayString<CAP> {
512520
*self
513521
}
@@ -518,8 +526,8 @@ impl<const CAP: usize> Clone for ArrayString<CAP>
518526
}
519527
}
520528

521-
impl<const CAP: usize> PartialOrd for ArrayString<CAP>
522-
{
529+
#[cfg_attr(rustfmt, rustfmt::skip)]
530+
impl<const CAP: usize> PartialOrd for ArrayString<CAP> {
523531
fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
524532
(**self).partial_cmp(&**rhs)
525533
}
@@ -529,8 +537,8 @@ impl<const CAP: usize> PartialOrd for ArrayString<CAP>
529537
fn ge(&self, rhs: &Self) -> bool { **self >= **rhs }
530538
}
531539

532-
impl<const CAP: usize> PartialOrd<str> for ArrayString<CAP>
533-
{
540+
#[cfg_attr(rustfmt, rustfmt::skip)]
541+
impl<const CAP: usize> PartialOrd<str> for ArrayString<CAP> {
534542
fn partial_cmp(&self, rhs: &str) -> Option<cmp::Ordering> {
535543
(**self).partial_cmp(rhs)
536544
}
@@ -540,8 +548,8 @@ impl<const CAP: usize> PartialOrd<str> for ArrayString<CAP>
540548
fn ge(&self, rhs: &str) -> bool { &**self >= rhs }
541549
}
542550

543-
impl<const CAP: usize> PartialOrd<ArrayString<CAP>> for str
544-
{
551+
#[cfg_attr(rustfmt, rustfmt::skip)]
552+
impl<const CAP: usize> PartialOrd<ArrayString<CAP>> for str {
545553
fn partial_cmp(&self, rhs: &ArrayString<CAP>) -> Option<cmp::Ordering> {
546554
self.partial_cmp(&**rhs)
547555
}
@@ -551,39 +559,37 @@ impl<const CAP: usize> PartialOrd<ArrayString<CAP>> for str
551559
fn ge(&self, rhs: &ArrayString<CAP>) -> bool { self >= &**rhs }
552560
}
553561

554-
impl<const CAP: usize> Ord for ArrayString<CAP>
555-
{
562+
impl<const CAP: usize> Ord for ArrayString<CAP> {
556563
fn cmp(&self, rhs: &Self) -> cmp::Ordering {
557564
(**self).cmp(&**rhs)
558565
}
559566
}
560567

561-
impl<const CAP: usize> FromStr for ArrayString<CAP>
562-
{
568+
impl<const CAP: usize> FromStr for ArrayString<CAP> {
563569
type Err = CapacityError;
564570

565571
fn from_str(s: &str) -> Result<Self, Self::Err> {
566572
Self::from(s).map_err(CapacityError::simplify)
567573
}
568574
}
569575

570-
#[cfg(feature="serde")]
576+
#[cfg(feature = "serde")]
571577
/// Requires crate feature `"serde"`
572-
impl<const CAP: usize> Serialize for ArrayString<CAP>
573-
{
578+
impl<const CAP: usize> Serialize for ArrayString<CAP> {
574579
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
575-
where S: Serializer
580+
where
581+
S: Serializer,
576582
{
577583
serializer.serialize_str(&*self)
578584
}
579585
}
580586

581-
#[cfg(feature="serde")]
587+
#[cfg(feature = "serde")]
582588
/// Requires crate feature `"serde"`
583-
impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP>
584-
{
589+
impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP> {
585590
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
586-
where D: Deserializer<'de>
591+
where
592+
D: Deserializer<'de>,
587593
{
588594
use serde::de::{self, Visitor};
589595
use std::marker::PhantomData;
@@ -598,15 +604,18 @@ impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP>
598604
}
599605

600606
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
601-
where E: de::Error,
607+
where
608+
E: de::Error,
602609
{
603610
ArrayString::from(v).map_err(|_| E::invalid_length(v.len(), &self))
604611
}
605612

606613
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
607-
where E: de::Error,
614+
where
615+
E: de::Error,
608616
{
609-
let s = str::from_utf8(v).map_err(|_| E::invalid_value(de::Unexpected::Bytes(v), &self))?;
617+
let s = str::from_utf8(v)
618+
.map_err(|_| E::invalid_value(de::Unexpected::Bytes(v), &self))?;
610619

611620
ArrayString::from(s).map_err(|_| E::invalid_length(s.len(), &self))
612621
}
@@ -616,8 +625,7 @@ impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP>
616625
}
617626
}
618627

619-
impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP>
620-
{
628+
impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP> {
621629
type Error = CapacityError<&'a str>;
622630

623631
fn try_from(f: &'a str) -> Result<Self, Self::Error> {
@@ -627,8 +635,7 @@ impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP>
627635
}
628636
}
629637

630-
impl<'a, const CAP: usize> TryFrom<fmt::Arguments<'a>> for ArrayString<CAP>
631-
{
638+
impl<'a, const CAP: usize> TryFrom<fmt::Arguments<'a>> for ArrayString<CAP> {
632639
type Error = CapacityError<fmt::Error>;
633640

634641
fn try_from(f: fmt::Arguments<'a>) -> Result<Self, Self::Error> {

0 commit comments

Comments
 (0)