Skip to content

Commit cdfd5d4

Browse files
committed
STYLE: format src
1 parent 5e9712a commit cdfd5d4

File tree

7 files changed

+263
-218
lines changed

7 files changed

+263
-218
lines changed

src/array_string.rs

+84-81
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');
@@ -373,10 +384,7 @@ impl<const CAP: usize> ArrayString<CAP>
373384
let len = self.len();
374385
let ptr = self.as_mut_ptr();
375386
unsafe {
376-
ptr::copy(
377-
ptr.add(next),
378-
ptr.add(idx),
379-
len - next);
387+
ptr::copy(ptr.add(next), ptr.add(idx), len - next);
380388
self.set_len(len - (next - idx));
381389
}
382390
ch
@@ -421,8 +429,7 @@ impl<const CAP: usize> ArrayString<CAP>
421429
}
422430
}
423431

424-
impl<const CAP: usize> Deref for ArrayString<CAP>
425-
{
432+
impl<const CAP: usize> Deref for ArrayString<CAP> {
426433
type Target = str;
427434
#[inline]
428435
fn deref(&self) -> &str {
@@ -433,8 +440,7 @@ impl<const CAP: usize> Deref for ArrayString<CAP>
433440
}
434441
}
435442

436-
impl<const CAP: usize> DerefMut for ArrayString<CAP>
437-
{
443+
impl<const CAP: usize> DerefMut for ArrayString<CAP> {
438444
#[inline]
439445
fn deref_mut(&mut self) -> &mut str {
440446
unsafe {
@@ -445,65 +451,64 @@ impl<const CAP: usize> DerefMut for ArrayString<CAP>
445451
}
446452
}
447453

448-
impl<const CAP: usize> PartialEq for ArrayString<CAP>
449-
{
454+
impl<const CAP: usize> PartialEq for ArrayString<CAP> {
450455
fn eq(&self, rhs: &Self) -> bool {
451456
**self == **rhs
452457
}
453458
}
454459

455-
impl<const CAP: usize> PartialEq<str> for ArrayString<CAP>
456-
{
460+
impl<const CAP: usize> PartialEq<str> for ArrayString<CAP> {
457461
fn eq(&self, rhs: &str) -> bool {
458462
&**self == rhs
459463
}
460464
}
461465

462-
impl<const CAP: usize> PartialEq<ArrayString<CAP>> for str
463-
{
466+
impl<const CAP: usize> PartialEq<ArrayString<CAP>> for str {
464467
fn eq(&self, rhs: &ArrayString<CAP>) -> bool {
465468
self == &**rhs
466469
}
467470
}
468471

469-
impl<const CAP: usize> Eq for ArrayString<CAP>
470-
{ }
472+
impl<const CAP: usize> Eq for ArrayString<CAP> {}
471473

472-
impl<const CAP: usize> Hash for ArrayString<CAP>
473-
{
474+
impl<const CAP: usize> Hash for ArrayString<CAP> {
474475
fn hash<H: Hasher>(&self, h: &mut H) {
475476
(**self).hash(h)
476477
}
477478
}
478479

479-
impl<const CAP: usize> Borrow<str> for ArrayString<CAP>
480-
{
481-
fn borrow(&self) -> &str { self }
480+
impl<const CAP: usize> Borrow<str> for ArrayString<CAP> {
481+
fn borrow(&self) -> &str {
482+
self
483+
}
482484
}
483485

484-
impl<const CAP: usize> BorrowMut<str> for ArrayString<CAP>
485-
{
486-
fn borrow_mut(&mut self) -> &mut str { self }
486+
impl<const CAP: usize> BorrowMut<str> for ArrayString<CAP> {
487+
fn borrow_mut(&mut self) -> &mut str {
488+
self
489+
}
487490
}
488491

489-
impl<const CAP: usize> AsRef<str> for ArrayString<CAP>
490-
{
491-
fn as_ref(&self) -> &str { self }
492+
impl<const CAP: usize> AsRef<str> for ArrayString<CAP> {
493+
fn as_ref(&self) -> &str {
494+
self
495+
}
492496
}
493497

494-
impl<const CAP: usize> fmt::Debug for ArrayString<CAP>
495-
{
496-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
498+
impl<const CAP: usize> fmt::Debug for ArrayString<CAP> {
499+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
500+
(**self).fmt(f)
501+
}
497502
}
498503

499-
impl<const CAP: usize> fmt::Display for ArrayString<CAP>
500-
{
501-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { (**self).fmt(f) }
504+
impl<const CAP: usize> fmt::Display for ArrayString<CAP> {
505+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
506+
(**self).fmt(f)
507+
}
502508
}
503509

504510
/// `Write` appends written data to the end of the string.
505-
impl<const CAP: usize> fmt::Write for ArrayString<CAP>
506-
{
511+
impl<const CAP: usize> fmt::Write for ArrayString<CAP> {
507512
fn write_char(&mut self, c: char) -> fmt::Result {
508513
self.try_push(c).map_err(|_| fmt::Error)
509514
}
@@ -513,8 +518,7 @@ impl<const CAP: usize> fmt::Write for ArrayString<CAP>
513518
}
514519
}
515520

516-
impl<const CAP: usize> Clone for ArrayString<CAP>
517-
{
521+
impl<const CAP: usize> Clone for ArrayString<CAP> {
518522
fn clone(&self) -> ArrayString<CAP> {
519523
*self
520524
}
@@ -525,8 +529,8 @@ impl<const CAP: usize> Clone for ArrayString<CAP>
525529
}
526530
}
527531

528-
impl<const CAP: usize> PartialOrd for ArrayString<CAP>
529-
{
532+
#[cfg_attr(rustfmt, rustfmt::skip)]
533+
impl<const CAP: usize> PartialOrd for ArrayString<CAP> {
530534
fn partial_cmp(&self, rhs: &Self) -> Option<cmp::Ordering> {
531535
(**self).partial_cmp(&**rhs)
532536
}
@@ -536,8 +540,8 @@ impl<const CAP: usize> PartialOrd for ArrayString<CAP>
536540
fn ge(&self, rhs: &Self) -> bool { **self >= **rhs }
537541
}
538542

539-
impl<const CAP: usize> PartialOrd<str> for ArrayString<CAP>
540-
{
543+
#[cfg_attr(rustfmt, rustfmt::skip)]
544+
impl<const CAP: usize> PartialOrd<str> for ArrayString<CAP> {
541545
fn partial_cmp(&self, rhs: &str) -> Option<cmp::Ordering> {
542546
(**self).partial_cmp(rhs)
543547
}
@@ -547,8 +551,8 @@ impl<const CAP: usize> PartialOrd<str> for ArrayString<CAP>
547551
fn ge(&self, rhs: &str) -> bool { &**self >= rhs }
548552
}
549553

550-
impl<const CAP: usize> PartialOrd<ArrayString<CAP>> for str
551-
{
554+
#[cfg_attr(rustfmt, rustfmt::skip)]
555+
impl<const CAP: usize> PartialOrd<ArrayString<CAP>> for str {
552556
fn partial_cmp(&self, rhs: &ArrayString<CAP>) -> Option<cmp::Ordering> {
553557
self.partial_cmp(&**rhs)
554558
}
@@ -558,39 +562,37 @@ impl<const CAP: usize> PartialOrd<ArrayString<CAP>> for str
558562
fn ge(&self, rhs: &ArrayString<CAP>) -> bool { self >= &**rhs }
559563
}
560564

561-
impl<const CAP: usize> Ord for ArrayString<CAP>
562-
{
565+
impl<const CAP: usize> Ord for ArrayString<CAP> {
563566
fn cmp(&self, rhs: &Self) -> cmp::Ordering {
564567
(**self).cmp(&**rhs)
565568
}
566569
}
567570

568-
impl<const CAP: usize> FromStr for ArrayString<CAP>
569-
{
571+
impl<const CAP: usize> FromStr for ArrayString<CAP> {
570572
type Err = CapacityError;
571573

572574
fn from_str(s: &str) -> Result<Self, Self::Err> {
573575
Self::from(s).map_err(CapacityError::simplify)
574576
}
575577
}
576578

577-
#[cfg(feature="serde")]
579+
#[cfg(feature = "serde")]
578580
/// Requires crate feature `"serde"`
579-
impl<const CAP: usize> Serialize for ArrayString<CAP>
580-
{
581+
impl<const CAP: usize> Serialize for ArrayString<CAP> {
581582
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
582-
where S: Serializer
583+
where
584+
S: Serializer,
583585
{
584586
serializer.serialize_str(&*self)
585587
}
586588
}
587589

588-
#[cfg(feature="serde")]
590+
#[cfg(feature = "serde")]
589591
/// Requires crate feature `"serde"`
590-
impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP>
591-
{
592+
impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP> {
592593
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
593-
where D: Deserializer<'de>
594+
where
595+
D: Deserializer<'de>,
594596
{
595597
use serde::de::{self, Visitor};
596598
use std::marker::PhantomData;
@@ -605,15 +607,18 @@ impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP>
605607
}
606608

607609
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
608-
where E: de::Error,
610+
where
611+
E: de::Error,
609612
{
610613
ArrayString::from(v).map_err(|_| E::invalid_length(v.len(), &self))
611614
}
612615

613616
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
614-
where E: de::Error,
617+
where
618+
E: de::Error,
615619
{
616-
let s = str::from_utf8(v).map_err(|_| E::invalid_value(de::Unexpected::Bytes(v), &self))?;
620+
let s = str::from_utf8(v)
621+
.map_err(|_| E::invalid_value(de::Unexpected::Bytes(v), &self))?;
617622

618623
ArrayString::from(s).map_err(|_| E::invalid_length(s.len(), &self))
619624
}
@@ -623,8 +628,7 @@ impl<'de, const CAP: usize> Deserialize<'de> for ArrayString<CAP>
623628
}
624629
}
625630

626-
impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP>
627-
{
631+
impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP> {
628632
type Error = CapacityError<&'a str>;
629633

630634
fn try_from(f: &'a str) -> Result<Self, Self::Error> {
@@ -634,8 +638,7 @@ impl<'a, const CAP: usize> TryFrom<&'a str> for ArrayString<CAP>
634638
}
635639
}
636640

637-
impl<'a, const CAP: usize> TryFrom<fmt::Arguments<'a>> for ArrayString<CAP>
638-
{
641+
impl<'a, const CAP: usize> TryFrom<fmt::Arguments<'a>> for ArrayString<CAP> {
639642
type Error = CapacityError<fmt::Error>;
640643

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

0 commit comments

Comments
 (0)