|
1 | 1 | #![cfg_attr(rustfmt, rustfmt_skip)]
|
2 | 2 |
|
3 | 3 | use std::{fmt, mem};
|
4 |
| -use std::borrow::Borrow; |
| 4 | +use std::borrow::{Borrow, Cow}; |
5 | 5 | use std::error::Error;
|
6 | 6 | use std::any::Any;
|
7 | 7 | use std::str::FromStr;
|
@@ -449,6 +449,24 @@ impl Into<String> for AsciiString {
|
449 | 449 | }
|
450 | 450 | }
|
451 | 451 |
|
| 452 | +impl<'a> From<Cow<'a,AsciiStr>> for AsciiString { |
| 453 | + fn from(cow: Cow<'a,AsciiStr>) -> AsciiString { |
| 454 | + cow.into_owned() |
| 455 | + } |
| 456 | +} |
| 457 | + |
| 458 | +impl From<AsciiString> for Cow<'static,AsciiStr> { |
| 459 | + fn from(string: AsciiString) -> Cow<'static,AsciiStr> { |
| 460 | + Cow::Owned(string) |
| 461 | + } |
| 462 | +} |
| 463 | + |
| 464 | +impl<'a> From<&'a AsciiStr> for Cow<'a,AsciiStr> { |
| 465 | + fn from(s: &'a AsciiStr) -> Cow<'a,AsciiStr> { |
| 466 | + Cow::Borrowed(s) |
| 467 | + } |
| 468 | +} |
| 469 | + |
452 | 470 | impl AsRef<AsciiStr> for AsciiString {
|
453 | 471 | #[inline]
|
454 | 472 | fn as_ref(&self) -> &AsciiStr {
|
@@ -524,6 +542,14 @@ impl<'a> FromIterator<&'a AsciiStr> for AsciiString {
|
524 | 542 | }
|
525 | 543 | }
|
526 | 544 |
|
| 545 | +impl<'a> FromIterator<Cow<'a, AsciiStr>> for AsciiString { |
| 546 | + fn from_iter<I: IntoIterator<Item = Cow<'a, AsciiStr>>>(iter: I) -> AsciiString { |
| 547 | + let mut buf = AsciiString::new(); |
| 548 | + buf.extend(iter); |
| 549 | + buf |
| 550 | + } |
| 551 | +} |
| 552 | + |
527 | 553 | impl Extend<AsciiChar> for AsciiString {
|
528 | 554 | fn extend<I: IntoIterator<Item = AsciiChar>>(&mut self, iterable: I) {
|
529 | 555 | let iterator = iterable.into_iter();
|
@@ -552,6 +578,17 @@ impl<'a> Extend<&'a AsciiStr> for AsciiString {
|
552 | 578 | }
|
553 | 579 | }
|
554 | 580 |
|
| 581 | +impl<'a> Extend<Cow<'a, AsciiStr>> for AsciiString { |
| 582 | + fn extend<I: IntoIterator<Item = Cow<'a,AsciiStr>>>(&mut self, iterable: I) { |
| 583 | + let iterator = iterable.into_iter(); |
| 584 | + let (lower_bound, _) = iterator.size_hint(); |
| 585 | + self.reserve(lower_bound); |
| 586 | + for s in iterator { |
| 587 | + self.push_str(&*s); |
| 588 | + } |
| 589 | + } |
| 590 | +} |
| 591 | + |
555 | 592 | impl<'a> Add<&'a AsciiStr> for AsciiString {
|
556 | 593 | type Output = AsciiString;
|
557 | 594 |
|
|
0 commit comments