Skip to content

Commit 41fb082

Browse files
tormolThomas Bahn
authored and
Thomas Bahn
committed
Implement BorrowMut and more AsRefs and AsMuts for AsciiString
* BorrowMut<AsciiStr> * AsMut<[AsciiChar]> * AsRef<[AsciiChar]> * AsRef<str>
1 parent b90cfad commit 41fb082

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/ascii_string.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(rustfmt, rustfmt_skip)]
22

33
use std::{fmt, mem};
4-
use std::borrow::{Borrow, Cow};
4+
use std::borrow::{Borrow, BorrowMut, Cow};
55
use std::error::Error;
66
use std::any::Any;
77
use std::str::FromStr;
@@ -418,6 +418,13 @@ impl Borrow<AsciiStr> for AsciiString {
418418
}
419419
}
420420

421+
impl BorrowMut<AsciiStr> for AsciiString {
422+
#[inline]
423+
fn borrow_mut(&mut self) -> &mut AsciiStr {
424+
&mut*self
425+
}
426+
}
427+
421428
impl From<Vec<AsciiChar>> for AsciiString {
422429
#[inline]
423430
fn from(vec: Vec<AsciiChar>) -> Self {
@@ -474,20 +481,41 @@ impl AsRef<AsciiStr> for AsciiString {
474481
}
475482
}
476483

484+
impl AsRef<[AsciiChar]> for AsciiString {
485+
#[inline]
486+
fn as_ref(&self) -> &[AsciiChar] {
487+
&self.vec
488+
}
489+
}
490+
477491
impl AsRef<[u8]> for AsciiString {
478492
#[inline]
479493
fn as_ref(&self) -> &[u8] {
480494
self.as_bytes()
481495
}
482496
}
483497

498+
impl AsRef<str> for AsciiString {
499+
#[inline]
500+
fn as_ref(&self) -> &str {
501+
self.as_str()
502+
}
503+
}
504+
484505
impl AsMut<AsciiStr> for AsciiString {
485506
#[inline]
486507
fn as_mut(&mut self) -> &mut AsciiStr {
487508
&mut *self
488509
}
489510
}
490511

512+
impl AsMut<[AsciiChar]> for AsciiString {
513+
#[inline]
514+
fn as_mut(&mut self) -> &mut [AsciiChar] {
515+
&mut self.vec
516+
}
517+
}
518+
491519
impl FromStr for AsciiString {
492520
type Err = AsAsciiStrError;
493521

0 commit comments

Comments
 (0)