版本配套 回退0.7.1

Signed-off-by: ljy9810 <longjianyin@h-partners.com>
This commit is contained in:
ljy9810
2025-08-29 14:39:19 +08:00
parent 94040379e7
commit aafa40de17
7 changed files with 14 additions and 39 deletions
-1
View File
@@ -33,7 +33,6 @@ jobs:
- 1.36.0 # Oldest supported with MaybeUninit
- 1.40.0 # Oldest supported with cfg(doctest)
- 1.51.0 # Oldest supported with ptr::addr_of!
- 1.65.0 # Oldest supported with stable const evaluation (sans cell)
- stable
- beta
- nightly
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "memoffset"
version = "0.8.0"
version = "0.7.1"
authors = ["Gilad Naaman <gilad.naaman@gmail.com>"]
description = "offset_of functionality for Rust structs."
license = "MIT"
+1 -1
View File
@@ -3,7 +3,7 @@
"Name": "memoffset",
"License": "Apache License V2.0",
"License File": "LICENSE",
"Version Number": "0.8.0",
"Version Number": "0.7.1",
"Owner": "fangting12@huawei.com",
"Upstream URL": "https://github.com/Gilnaa/memoffset",
"Description": "A Rust library that provides support for calculating offsets in memory."
+6 -26
View File
@@ -7,7 +7,6 @@ C-Like `offset_of` functionality for Rust structs.
Introduces the following macros:
* `offset_of!` for obtaining the offset of a member of a struct.
* `offset_of_tuple!` for obtaining the offset of a member of a tuple. (Requires Rust 1.20+)
* `offset_of_union!` for obtaining the offset of a member of a union.
* `span_of!` for obtaining the range that a field, or fields, span.
`memoffset` works under `no_std` environments.
@@ -17,7 +16,7 @@ Add the following dependency to your `Cargo.toml`:
```toml
[dependencies]
memoffset = "0.8"
memoffset = "0.7"
```
These versions will compile fine with rustc versions greater or equal to 1.19.
@@ -46,39 +45,20 @@ fn main() {
}
```
## Usage in constants ##
`memoffset` has support for compile-time `offset_of!` on rust>=1.65, or on older nightly compilers.
## Feature flags ##
### Usage on stable Rust ###
Constant evaluation is automatically enabled and avilable on stable compilers starting with rustc 1.65.
### Usage in constants ###
`memoffset` has **experimental** support for compile-time `offset_of!` on a nightly compiler.
This is an incomplete implementation with one caveat:
Due to dependence on [`#![feature(const_refs_to_cell)]`](https://github.com/rust-lang/rust/issues/80384), you cannot get the offset of a `Cell` field in a const-context.
This means that if need to get the offset of a cell, you'll have to remain on nightly for now.
### Usage on recent nightlies ###
If you're using a new-enough nightly and you require the ability to get the offset of a `Cell`,
you'll have to enable the `unstable_const` cargo feature, as well as enabling `const_refs_to_cell` in your crate root.
Do note that `unstable_const` is an unstable feature that is set to be removed in a future version of `memoffset`.
In order to use it, you must enable the `unstable_const` crate feature and several compiler features.
Cargo.toml:
```toml
[dependencies.memoffset]
version = "0.8"
version = "0.7"
features = ["unstable_const"]
```
Your crate root: (`lib.rs`/`main.rs`)
```rust,ignore
#![feature(const_refs_to_cell)]
```
### Usage on older nightlies ###
In order to use it on an older nightly compiler, you must enable the `unstable_const` crate feature and several compiler features.
Your crate root: (`lib.rs`/`main.rs`)
```rust,ignore
#![feature(const_ptr_offset_from, const_refs_to_cell)]
-3
View File
@@ -19,7 +19,4 @@ fn main() {
if ac.probe_rustc_version(1, 51) {
println!("cargo:rustc-cfg=raw_ref_macros");
}
if ac.probe_rustc_version(1, 65) {
println!("cargo:rustc-cfg=stable_const");
}
}
+2 -3
View File
@@ -57,10 +57,9 @@
#![no_std]
#![cfg_attr(
all(feature = "unstable_const", not(stable_const)),
feature(const_ptr_offset_from)
feature = "unstable_const",
feature(const_ptr_offset_from, const_refs_to_cell)
)]
#![cfg_attr(feature = "unstable_const", feature(const_refs_to_cell))]
#[macro_use]
#[cfg(doctests)]
+4 -4
View File
@@ -46,7 +46,7 @@ macro_rules! _memoffset__let_base_ptr {
}
/// Macro to compute the distance between two pointers.
#[cfg(any(feature = "unstable_const", stable_const))]
#[cfg(feature = "unstable_const")]
#[macro_export]
#[doc(hidden)]
macro_rules! _memoffset_offset_from_unsafe {
@@ -58,7 +58,7 @@ macro_rules! _memoffset_offset_from_unsafe {
unsafe { (field as *const u8).offset_from(base as *const u8) as usize }
}};
}
#[cfg(not(any(feature = "unstable_const", stable_const)))]
#[cfg(not(feature = "unstable_const"))]
#[macro_export]
#[doc(hidden)]
macro_rules! _memoffset_offset_from_unsafe {
@@ -312,7 +312,7 @@ mod tests {
assert_eq!(f_ptr as usize + 0, raw_field_union!(f_ptr, Foo, c) as usize);
}
#[cfg(any(feature = "unstable_const", stable_const))]
#[cfg(feature = "unstable_const")]
#[test]
fn const_offset() {
#[repr(C)]
@@ -337,7 +337,7 @@ mod tests {
assert_eq!([0; offset_of!(Foo, b)].len(), 4);
}
#[cfg(any(feature = "unstable_const", stable_const))]
#[cfg(feature = "unstable_const")]
#[test]
fn const_fn_offset() {
const fn test_fn() -> usize {