ok/jj
1
0
Fork 0
forked from mirrors/jj

cargo: add ref-cast dependency

It helps to implement transparent conversion from &str to &Wrapped(str). We
could instead wrap the reference as Wrapped<'a>(&'a str), but it has various
drawbacks. Notably we can't implement Borrow and Deref because these traits
require a reference in return position.

Since the unsafe bits are pretty small, we can instead implement cast functions
without using the ref-cast crate. However, I believe we'll trust ref-cast more
than hand-crafted unsafe code.

https://crates.io/crates/ref-cast
https://docs.rs/ref-cast/1.0.20/ref_cast/attr.ref_cast_custom.html
This commit is contained in:
Yuya Nishihara 2023-11-25 18:05:55 +09:00
parent b7543f8a08
commit b5b01f4dd7
3 changed files with 23 additions and 0 deletions

21
Cargo.lock generated
View file

@ -1681,6 +1681,7 @@ dependencies = [
"rand", "rand",
"rand_chacha", "rand_chacha",
"rayon", "rayon",
"ref-cast",
"regex", "regex",
"rustix", "rustix",
"serde", "serde",
@ -2380,6 +2381,26 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "ref-cast"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acde58d073e9c79da00f2b5b84eed919c8326832648a5b109b3fce1bb1175280"
dependencies = [
"ref-cast-impl",
]
[[package]]
name = "ref-cast-impl"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7473c2cfcf90008193dd0e3e16599455cb601a9fce322b5bb55de799664925"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.37",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.2" version = "1.10.2"

View file

@ -65,6 +65,7 @@ prost-build = "0.11.9"
rand = "0.8.5" rand = "0.8.5"
rand_chacha = "0.3.1" rand_chacha = "0.3.1"
rayon = "1.8.0" rayon = "1.8.0"
ref-cast = "1.0.20"
regex = "1.10.2" regex = "1.10.2"
rpassword = "7.3.1" rpassword = "7.3.1"
rustix = { version = "0.38.25", features = ["fs"] } rustix = { version = "0.38.25", features = ["fs"] }

View file

@ -43,6 +43,7 @@ prost = { workspace = true }
rand = { workspace = true } rand = { workspace = true }
rand_chacha = { workspace = true } rand_chacha = { workspace = true }
rayon = { workspace = true } rayon = { workspace = true }
ref-cast = { workspace = true }
regex = { workspace = true } regex = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }