mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-27 16:07:46 +00:00
Implementing From<Arc<str>> for SmolStr and From<SmolStr> for Arc<str>
Also adding one test to verify
This commit is contained in:
parent
b04898eb32
commit
ced7e87db1
@ -334,6 +334,13 @@ impl From<Box<str>> for SmolStr {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Arc<str>> for SmolStr {
|
||||
#[inline]
|
||||
fn from(s: Arc<str>) -> SmolStr {
|
||||
SmolStr(Repr::Heap(s))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Cow<'a, str>> for SmolStr {
|
||||
#[inline]
|
||||
fn from(s: Cow<'a, str>) -> SmolStr {
|
||||
@ -341,6 +348,16 @@ impl<'a> From<Cow<'a, str>> for SmolStr {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SmolStr> for Arc<str> {
|
||||
#[inline(always)]
|
||||
fn from(text: SmolStr) -> Self {
|
||||
match text.0 {
|
||||
Repr::Heap(data) => data,
|
||||
_ => text.as_str().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<SmolStr> for String {
|
||||
#[inline(always)]
|
||||
fn from(text: SmolStr) -> Self {
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use proptest::{prop_assert, prop_assert_eq, proptest};
|
||||
|
||||
use smol_str::SmolStr;
|
||||
@ -21,7 +23,11 @@ fn assert_traits() {
|
||||
fn conversions() {
|
||||
let s: SmolStr = "Hello, World!".into();
|
||||
let s: String = s.into();
|
||||
assert_eq!(s, "Hello, World!")
|
||||
assert_eq!(s, "Hello, World!");
|
||||
|
||||
let s: SmolStr = Arc::<str>::from("Hello, World!").into();
|
||||
let s: Arc<str> = s.into();
|
||||
assert_eq!(s.as_ref(), "Hello, World!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user