Send, Sync, Borrow, AsRef, remove Cargo.lock

This commit is contained in:
missing 2022-12-26 10:42:29 -06:00
parent eb64585d3c
commit 23f0c5ddd8
5 changed files with 19 additions and 9 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target
Cargo.lock

7
Cargo.lock generated
View File

@ -1,7 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "stringish"
version = "0.1.0"

View File

@ -1,6 +1,6 @@
[package]
name = "stringish"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
description = "A smaller and easier copy-on-write string"
repository = "https://git.karx.xyz/missing/stringish"

View File

@ -1,5 +1,5 @@
use std::{
borrow::Cow,
borrow::{Borrow, Cow},
fmt::{Debug, Display},
hash::Hash,
};
@ -101,3 +101,15 @@ macro_rules! impl_eq_ord {
}
impl_eq_ord!(str, &'a str, String, Cow<'a, str>);
impl AsRef<str> for Stringish {
fn as_ref(&self) -> &str {
&self[..]
}
}
impl Borrow<str> for Stringish {
fn borrow(&self) -> &str {
&self[..]
}
}

View File

@ -47,6 +47,10 @@ pub struct Stringish {
cap: usize,
}
// SAFETY: this can be `Send + Sync` for the same reasons `String` can be
unsafe impl Send for Stringish {}
unsafe impl Sync for Stringish {}
impl Drop for Stringish {
fn drop(&mut self) {
if let Some(true) = self.is_owned() {