mirror of
https://github.com/openharmony/third_party_rust_memoffset.git
synced 2026-07-18 12:25:36 -04:00
weekly_20251006
版本配套 回退0.7.1
Created-by: dragonswordy
Commit-by: ljy9810
Merged-by: openharmony_ci
Description: ### 一、内容说明(相关的Issue)
### 二、建议测试周期和提测地址
建议测试完成时间:xxxx.xx.xx
投产上线时间:xxxx.xx.xx
提测地址:CI环境/压测环境
测试账号:
### 三、变更内容
* 3.1 关联PR列表
* 3.2 数据库和部署说明
1. 常规更新
2. 重启unicorn
3. 重启sidekiq
4. 迁移任务:是否有迁移任务,没有写 "无"
5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无"
* 3.4 其他技术优化内容(做了什么,变更了什么)
- 重构了 xxxx 代码
- xxxx 算法优化
* 3.5 废弃通知(什么字段、方法弃用?)
* 3.6 后向不兼容变更(是否有无法向后兼容的变更?)
### 四、研发自测点(自测哪些?冒烟用例全部自测?)
自测测试结论:
### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)
检查点:
| 需求名称 | 是否影响xx公共模块 | 是否需要xx功能 | 需求升级是否依赖其他子产品 |
|------|------------|----------|---------------|
| xxx | 否 | 需要 | 不需要 |
| | | | |
接口测试:
性能测试:
并发测试:
其他:
See merge request: openharmony/third_party_rust_memoffset!3
memoffset
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+)span_of!for obtaining the range that a field, or fields, span.
memoffset works under no_std environments.
Usage
Add the following dependency to your Cargo.toml:
[dependencies]
memoffset = "0.7"
These versions will compile fine with rustc versions greater or equal to 1.19.
Examples
use memoffset::{offset_of, span_of};
#[repr(C, packed)]
struct Foo {
a: u32,
b: u32,
c: [u8; 5],
d: u32,
}
fn main() {
assert_eq!(offset_of!(Foo, b), 4);
assert_eq!(offset_of!(Foo, d), 4+4+5);
assert_eq!(span_of!(Foo, a), 0..4);
assert_eq!(span_of!(Foo, a .. c), 0..8);
assert_eq!(span_of!(Foo, a ..= c), 0..13);
assert_eq!(span_of!(Foo, ..= d), 0..17);
assert_eq!(span_of!(Foo, b ..), 4..17);
}
Feature flags
Usage in constants
memoffset has experimental support for compile-time offset_of! on a nightly compiler.
In order to use it, you must enable the unstable_const crate feature and several compiler features.
Cargo.toml:
[dependencies.memoffset]
version = "0.7"
features = ["unstable_const"]
Your crate root: (lib.rs/main.rs)
#![feature(const_ptr_offset_from, const_refs_to_cell)]
Languages
Rust
100%