diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/field-offset/README.md | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/field-offset/README.md')
-rw-r--r-- | vendor/field-offset/README.md | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/field-offset/README.md b/vendor/field-offset/README.md new file mode 100644 index 000000000..8ebdf7903 --- /dev/null +++ b/vendor/field-offset/README.md @@ -0,0 +1,34 @@ +# field-offset: safe pointer-to-member functionality
+
+This crate implements an `offset_of!(...)` macro which safely encapsulates
+a pointer-to-member.
+
+Example:
+```rust
+struct Foo {
+ x: u32,
+ y: f64
+}
+
+let foo_y = offset_of!(Foo => y);
+
+let mut a = Foo { x: 1, y: 2.0 };
+
+*foo_y.apply_mut(&mut a) = 3.0;
+
+assert!(a.y == 3.0);
+```
+
+The macro returns an instance of `FieldOffset<T, U>`, which represents a
+pointer to a field of type `U` within a containing type, `T`.
+
+The `FieldOffset` type implements `Add`. Applying the resulting field offset
+is equivalent to applying the first field offset, then applying the second
+field offset.
+
+The macro also supports accessing nested fields:
+
+```rust
+let bar_foo_y = offset_of!(Bar => foo: Foo => y);
+```
+
|