Skip to content

Commit b75cfe1

Browse files
committed
impl AsRef
1 parent 618a2be commit b75cfe1

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/lib.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,23 @@ impl PartialEq<ColdString> for &str {
256256
}
257257
}
258258

259+
impl AsRef<str> for ColdString {
260+
#[inline]
261+
fn as_ref(&self) -> &str {
262+
self.as_str()
263+
}
264+
}
265+
266+
impl AsRef<[u8]> for ColdString {
267+
#[inline]
268+
fn as_ref(&self) -> &[u8] {
269+
self.as_bytes()
270+
}
271+
}
272+
259273
#[cfg(test)]
260274
mod tests {
261275
use super::*;
262-
use core::hash::BuildHasher;
263276

264277
#[test]
265278
fn test_layout() {
@@ -282,8 +295,11 @@ mod tests {
282295
assert_eq!(cs.len(), s.len());
283296
assert_eq!(cs.len() < 8, cs.is_inline());
284297
assert_eq!(cs.clone(), cs);
285-
let bh = core::hash::RandomState::new();
286-
assert_eq!(bh.hash_one(&cs), bh.hash_one(&cs.clone()));
298+
if cfg!(feature = "std") {
299+
use core::hash::BuildHasher;
300+
let bh = std::hash::RandomState::new();
301+
assert_eq!(bh.hash_one(&cs), bh.hash_one(&cs.clone()));
302+
}
287303
assert_eq!(cs, s);
288304
assert_eq!(s, cs);
289305
assert_eq!(cs, *s);

0 commit comments

Comments
 (0)