Skip to content

Commit 0a57176

Browse files
committed
Initial commit of tcast crate
1 parent 4ffb4e4 commit 0a57176

File tree

7 files changed

+620
-0
lines changed

7 files changed

+620
-0
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ members = [
7070
"utils/litemap",
7171
"utils/resb",
7272
"utils/tinystr",
73+
"utils/tcast",
7374
"utils/tzif",
7475
"utils/potential_utf",
7576
"utils/writeable",
@@ -299,6 +300,7 @@ rand = "0.9"
299300
rand_distr = "0.5"
300301
rand_pcg = "0.9"
301302
rayon = "1.3.0"
303+
ref_cast = "1.0"
302304
regex = "1.12.2"
303305
rkyv = "0.7"
304306
rmp-serde = "1.2.0"

utils/tcast/Cargo.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# This file is part of ICU4X. For terms of use, please see the file
2+
# called LICENSE at the top level of the ICU4X source tree
3+
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4+
5+
[package]
6+
name = "tcast"
7+
description = "Cast transparent wrappers between their inner and outer types"
8+
version = "0.1.0"
9+
authors = ["Shane F Carr <shane@unicode.org>"]
10+
categories = ["rust-patterns", "no-std", "no-std::no-alloc"]
11+
keywords = ["transparent", "cast", "ref", "box", "dst"]
12+
13+
edition.workspace = true
14+
include.workspace = true
15+
license.workspace = true
16+
repository.workspace = true
17+
rust-version = "1.71.1"
18+
19+
[lib]
20+
proc-macro = true
21+
path = "src/lib.rs"
22+
23+
[package.metadata.workspaces]
24+
independent = true
25+
26+
[package.metadata.docs.rs]
27+
all-features = true
28+
29+
[dependencies]
30+
proc-macro2 = { workspace = true }
31+
quote = { workspace = true }
32+
syn = { workspace = true, features = ["fold"] }
33+
34+
[dev-dependencies]
35+
36+
[lints]
37+
workspace = true

utils/tcast/LICENSE

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
UNICODE LICENSE V3
2+
3+
COPYRIGHT AND PERMISSION NOTICE
4+
5+
Copyright © 2020-2024 Unicode, Inc.
6+
7+
NOTICE TO USER: Carefully read the following legal agreement. BY
8+
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
9+
SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
10+
TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
11+
DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
12+
13+
Permission is hereby granted, free of charge, to any person obtaining a
14+
copy of data files and any associated documentation (the "Data Files") or
15+
software and any associated documentation (the "Software") to deal in the
16+
Data Files or Software without restriction, including without limitation
17+
the rights to use, copy, modify, merge, publish, distribute, and/or sell
18+
copies of the Data Files or Software, and to permit persons to whom the
19+
Data Files or Software are furnished to do so, provided that either (a)
20+
this copyright and permission notice appear with all copies of the Data
21+
Files or Software, or (b) this copyright and permission notice appear in
22+
associated Documentation.
23+
24+
THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
25+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
27+
THIRD PARTY RIGHTS.
28+
29+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
30+
BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
31+
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
32+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
33+
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
34+
FILES OR SOFTWARE.
35+
36+
Except as contained in this notice, the name of a copyright holder shall
37+
not be used in advertising or otherwise to promote the sale, use or other
38+
dealings in these Data Files or Software without prior written
39+
authorization of the copyright holder.
40+
41+
SPDX-License-Identifier: Unicode-3.0
42+
43+
44+
45+
Portions of ICU4X may have been adapted from ICU4C and/or ICU4J.
46+
ICU 1.8.1 to ICU 57.1 © 1995-2016 International Business Machines Corporation and others.

utils/tcast/README.md

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use tcast::TransparentCast;
2+
3+
#[derive(Debug, TransparentCast)]
4+
#[tcast(std)]
5+
#[repr(transparent)]
6+
struct Greeting<'a, T>(&'a T);
7+
8+
fn main() {
9+
let inner = &55u8;
10+
let g = Greeting::<u8>::tcast_ref(&inner);
11+
println!("{g:?}");
12+
}

0 commit comments

Comments
 (0)