Skip to content

Commit 679bd75

Browse files
0.2.9 (stable): Links to work on both GitHub and rustdoc/crates.io (part 3)
1 parent 5f7ed12 commit 679bd75

File tree

5 files changed

+71
-38
lines changed

5 files changed

+71
-38
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ behind `main`. See also [CONTRIBUTING.md](CONTRIBUTING.md).
1313
`ndd::infer::NonDeDuplicatedStr` and `ndd::infer::NonDeDuplicatedCStr`
1414
-->
1515

16+
## 0.2.9 (stable)
17+
18+
`README.md` links to work on both GitHub and `rustdoc` or `crates.io` (more).
19+
1620
## 0.2.8 (stable)
1721

1822
`README.md` links to work on both GitHub and `rustdoc` or `crates.io`.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ndd"
3-
version = "0.2.8"
3+
version = "0.2.9"
44
edition = "2024"
55

66
license = "BSD-2-Clause OR Apache-2.0 OR MIT"

README.md

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ However, there is a problem (caused by de-duplication in `release`, and for some
3737
or `miri). It affects ("ordinary") `const` values/expressions that equal in value to any `static`
3838
(whether it's a `static` variable, or a static literal), which may be your designated `static`.
3939
Rust/LLVM re-uses address of one such matching `static` for references to any equal value(s) defined
40-
as `const`. See a test [`src/lib.rs` ->
41-
`addresses_not_unique_between_const_and_static()`](https://github.com/peter-lyons-kehl/ndd/blob/26d743d9b7bbaf41155e00174f8827efca5d5f32/src/lib.rs#L95).
42-
Such `const`, `static` or literal could be in 3rd party code, even private. (See
43-
[`cross_crate_demo_bug/`](https://github.com/peter-lyons-kehl/ndd/tree/main/cross_crate_demo_bug))!
40+
as `const`. See [`src/lib.rs` -> `u8_global_const_and_global_static_release()`]. Such `const`,
41+
`static` or literal could be in 3rd party code, even private. (See [`cross_crate_demo_bug/`].)
4442

4543
Things get worse: `dev` builds don't have this consistent:
4644

@@ -71,29 +69,30 @@ opt-level = 2
7169

7270
## Solution
7371

74-
`ndd:NonDeDuplicated` uses
75-
[`core::cell::Cell`](https://doc.rust-lang.org/nightly/core/cell/struct.Cell.html) to hold the data
76-
passed in by the user. There is no mutation and no mutation access. The only access it gives to the
77-
inner data is through shared references.
72+
[`ndd::NonDeDuplicated`] uses [`core::cell::Cell`] to hold the data passed in by the user. There is no
73+
mutation and no mutation access. The only access it gives to the inner data is through shared
74+
references.
7875

79-
Unlike `Cell` (and friends), `NonDeDuplicated` **does** implement
80-
[`core::marker::Sync`](https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html) (if the inner
81-
data's type implements `Send` and `Sync`). It can safely do so, because it never provides mutable
82-
access, and it never mutates the inner data. That is similar to how
83-
[`std::sync::Mutex`](https://doc.rust-lang.org/nightly/std/sync/struct.Mutex.html#impl-Sync-for-Mutex%3CT%3E)
76+
Unlike `Cell` (and friends), `NonDeDuplicated` **does** implement [`core::marker::Sync`] (if the
77+
inner data's type implements `Send` and `Sync`). It can safely do so, because it never provides
78+
mutable access, and it never mutates the inner data. That is similar to how [`std::sync::Mutex`]
8479
implements `Sync`, too.
8580

86-
See [`src/lib.rs` ->
87-
`tests_behavior_with_ndd`](https://github.com/search?q=repo%3Apeter-lyons-kehl%2Fndd+tests_behavior_with_ndd+path%3Asrc%2Flib.rs&type=code).
81+
See [`src/lib.rs` -> `tests_behavior_with_ndd`].
8882

8983
## Use
9084

91-
Use `ndd::NonDeDuplicated` to wrap your static data. Use it for (immutable) `static` variables only.
92-
Do **not** use it for locals or on heap. That is validated by implementation of
93-
[core::ops::Drop](https://doc.rust-lang.org/nightly/core/ops/trait.Drop.html), which `panic`-s in
94-
`dev` builds.
85+
Use [`ndd::NonDeDuplicated`] to wrap your static data (other than string literals or C string
86+
literals). Use it for (immutable) `static` variables only. Do **not** use it for locals or on heap.
87+
That is validated by implementation of [`core::ops::Drop`], which `panic`s in `dev` builds.
9588

96-
See unit tests in [src/lib.rs](src/lib.rs).
89+
Use [`ndd::NonDeDuplicatedStr`] and [`ndd::NonDeDuplicatedCStr`] to wrap static string slices
90+
(`&str`) and C strings (owned bytes that defer to `&CStr`). These two types need a `const` generic
91+
parameter, which is the length (in bytes). There is no way around this (in stable Rust). On
92+
`nightly` Rust you can use `ndd::infer:NonDeDuplicatedStr` and `ndd::infer:NonDeDuplicatedCStr` from
93+
**odd-numbered** (`-nightly`) version of `ndd` instead.
94+
95+
See unit tests in [`src/lib.rs`], and [`cross_crate_demo_fix/callee/src/lib.rs`].
9796

9897
## Compatibility
9998

@@ -103,7 +102,7 @@ See unit tests in [src/lib.rs](src/lib.rs).
103102

104103
### Stable is always forward compatible
105104

106-
`ndd` is planned to be always below version `1.0`. (If a need arises for big incompatible
105+
`ndd` is planned to be always below version `1.0`. (If a need ever arises for big incompatible
107106
functionality, that can go in a new crate.)
108107

109108
That allows you to specify `ndd` as a dependency with version `0.*`, which will match ANY **major**
@@ -154,7 +153,7 @@ versions `1.0` or higher.
154153
trick](https://github.com/dtolnay/semver-trick). See also [The Cargo Book > Dependency
155154
Resolution](https://rustwiki.org/en/cargo/reference/resolver.html#version-incompatibility-hazards).
156155

157-
However, the only type exported from `ndd` is `ndd::NonDeDuplicated`. It is a zero-cost wrapper
156+
However, the only type exported from `ndd` is [`ndd::NonDeDuplicated`]. It is a zero-cost wrapper
158157
suitable for immutable `static` variables. It is normally not being passed around as a
159158
parameter/return type or a composite type. And its functions can get inlined/optimized away. So,
160159
there shouldn't be any big binary size/speed difference, or usability difference, if there happen
@@ -206,29 +205,26 @@ use an asterisk mask for the minor version, like `0.2.*`. But then you lose auto
206205

207206
### Nightly functionality
208207

209-
Functionality of odd-numbered major (`-nightly`) versions is always subject to change.
208+
WARNING: Functionality of odd-numbered major (`-nightly`) versions is always subject to change!
210209

211-
The following extra functionality is available on `0.3.1-nightly`. You need `nightly` Rust toolchain
212-
(of course).
210+
The following extra functionality is available on `0.3.5-nightly`. Of course, you need `nightly`
211+
Rust toolchain.
213212

214213
#### as_array_of_cells
215214

216-
`ndd::NonDeDuplicated` has function `as_array_of_cells`, similar to Rust's
217-
[`core::cell::Cell::as_array_of_cells`](https://doc.rust-lang.org/nightly/core/cell/struct.Cell.html#method.as_array_of_cells)
218-
(which will, hopefully, become stable in 1.91).
215+
[`ndd::NonDeDuplicated`] has function `as_array_of_cells`, similar to Rust's
216+
[`core::cell::Cell::as_array_of_cells`] (which will, hopefully, become stable in Rust 1.91).
219217

220218
#### as_slice_of_cells
221219

222-
Similar to `as_array_of_cells`, `ndd::NonDeDuplicated` has function `as_slice_of_cells`. That
220+
Similar to `as_array_of_cells`, [`ndd::NonDeDuplicated`] has function `as_slice_of_cells`. That
223221
**can** be stable with with Rust `1.88`+. However, to simplify versioning, it's bundled in
224222
`-nightly` together with `as_array_of_cells`. If you need it earlier, get in touch.
225223

226224
#### const Deref and From
227225

228-
[core::ops::Deref](https://doc.rust-lang.org/nightly/core/ops/trait.Deref.html) and
229-
[core::convert::From](https://doc.rust-lang.org/nightly/core/convert/trait.From.html) are
230-
implemented as `const`. As of mid 2025, `const` traits are having high traction in Rust. Hopefully
231-
this will be stable not in years, but sooner.
226+
[`core::ops::Deref`] and [`core::convert::From`] are implemented as `const`. As of mid 2025, `const`
227+
traits are having high traction in Rust. Hopefully this will be stable not in years, but sooner.
232228

233229
These traits are **not** implemented in stable versions at all. Why? Because `ndd` types are
234230
intended for `static` variables, so non-`const` functions don't help us.
@@ -287,14 +283,32 @@ Used by
287283
## Updates
288284

289285
Please subscribe for low frequency updates at
290-
[#2](https://github.com/peter-lyons-kehl/ndd/issues/2).
286+
[peter-lyons-kehl/ndd/issues#2](https://github.com/peter-lyons-kehl/ndd/issues/2).
291287

292288
## Side fruit
293289

294290
The following side fruit is `std`-only, but related: `std::sync::mutex::data_ptr(&self)` is now
295291
`const` function: pull request
296292
[rust-lang/rust#146904](https://github.com/rust-lang/rust/pull/146904).
297293

294+
<!-- Link URLs -->
298295
[`core::ptr::eq`]: https://doc.rust-lang.org/1.86.0/core/ptr/fn.eq.html
299296
[`core::ptr::addr_eq`]: https://doc.rust-lang.org/1.86.0/core/ptr/fn.addr_eq.html
297+
<!-- The following works also on https://crates.io/crates/ndd auto-magically: -->
300298
[`src/lib.rs` -> `addresses_unique_between_statics()`]: src/lib.rs#L246
299+
[`src/lib.rs` -> `u8_global_const_and_global_static_release()`]: src/lib.rs#L258
300+
[`cross_crate_demo_bug/`]: cross_crate_demo_bug/
301+
[`core::cell::Cell`]: https://doc.rust-lang.org/1.86.0/core/cell/struct.Cell.html
302+
[`core::marker::Sync`]: https://doc.rust-lang.org/1.86.0/core/marker/trait.Sync.html
303+
[`std::sync::Mutex`]: https://doc.rust-lang.org/1.86.0/std/sync/struct.Mutex.html#impl-Sync-for-Mutex<T>
304+
[`src/lib.rs` -> `tests_behavior_with_ndd`]: src/lib.rs#L339
305+
[`core::ops::Drop`]: https://doc.rust-lang.org/1.86.0/core/ops/trait.Drop.html
306+
[`src/lib.rs`]: src/lib.rs
307+
[`ndd::NonDeDuplicated`]: https://docs.rs/ndd/latest/ndd/type.NonDeDuplicated.html
308+
[`ndd::NonDeDuplicatedStr`]: https://docs.rs/ndd/latest/ndd/type.NonDeDuplicatedStr.html
309+
[`ndd::NonDeDuplicatedCStr`]: https://docs.rs/ndd/latest/ndd/type.NonDeDuplicatedCStr.html
310+
[`cross_crate_demo_fix/callee/src/lib.rs`]: cross_crate_demo_fix/callee/src/lib.rs
311+
<!-- nightly-only: -->
312+
[`core::cell::Cell::as_array_of_cells`]: https://doc.rust-lang.org/nightly/core/cell/struct.Cell.html#method.as_array_of_cells
313+
[`core::ops::Deref`]: https://doc.rust-lang.org/nightly/core/ops/trait.Deref.html
314+
[`core::convert::From`]: https://doc.rust-lang.org/nightly/core/convert/trait.From.html

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
// OVerride links, so that rustdoc can point them locally (or to docs.io, if run on docs.io).
2-
//! [`src/lib.rs` -> `addresses_unique_between_statics()`]:
3-
//! https://github.com/peter-lyons-kehl/ndd/blob/main/src/lib.rs#L246
2+
//! [`src/lib.rs` -> `addresses_unique_between_statics()`]: https://github.com/peter-lyons-kehl/ndd/blob/main/src/lib.rs#L246
3+
//! [`src/lib.rs` -> `u8_global_const_and_global_static_release()`]: https://github.com/peter-lyons-kehl/ndd/blob/main/src/lib.rs#L258
4+
//! [`cross_crate_demo_bug/`]: https://github.com/peter-lyons-kehl/ndd/tree/main/cross_crate_demo_bug
5+
//! [`core::cell::Cell`]: core::cell::Cell
6+
//! [`core::marker::Sync`]: core::marker::Sync
7+
//! [`std::sync::Mutex`]: std::sync::Mutex#impl-Sync-for-Mutex<T>
8+
//! [`src/lib.rs` -> `tests_behavior_with_ndd`]: https://github.com/peter-lyons-kehl/ndd/blob/main/src/lib.rs#L339
9+
//! [`core::ops::Drop`]: core::ops::Drop
10+
//! [`src/lib.rs`]: https://github.com/peter-lyons-kehl/ndd/blob/main/src/lib.rs
11+
//! [`ndd::NonDeDuplicated`]: crate::NonDeDuplicated
12+
//! [`ndd::NonDeDuplicatedStr`]: crate::NonDeDuplicatedStr
13+
//! [`ndd::NonDeDuplicatedCStr`]: crate::NonDeDuplicatedCStr
14+
//! [`cross_crate_demo_fix/callee/src/lib.rs`]: https://github.com/peter-lyons-kehl/ndd/blob/main/cross_crate_demo_fix/callee/src/lib.rs
15+
//! <!-- as_array_of_cells is on nightly toolchain only -->
16+
//! [`core::cell::Cell::as_array_of_cells`]: core::cell::Cell::as_array_of_cells
17+
//! [`core::ops::Deref`]: core::ops::Deref
18+
//! [`core::convert::From`]: core::convert::From
419
#![doc = include_str!("../README.md")]
520
#![cfg_attr(not(any(doc, test)), no_std)]
621
#![allow(incomplete_features)]

0 commit comments

Comments
 (0)