-
Notifications
You must be signed in to change notification settings - Fork 15
Get underling values of Fields #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a6786ef
Add support for using Field* as their underlying type
nickpdemarco 0807f30
Documentation for new field support
nickpdemarco f8fcbf6
Tests for field support with underlying read
nickpdemarco d4d558a
Update expected_output.txt to account for extra newline in test output
nickpdemarco dab8088
Move field documentation to new file
nickpdemarco 36cfa7f
Remove read and as_ref methods on fields
nickpdemarco c5b992d
Switch to rust stable to work around rust-lang/rust#115746
nickpdemarco 94d0ec9
Use clone to copy std::string
nickpdemarco ea38b4c
Update test expectation
nickpdemarco 2128929
Install lld and explicitly set CC for clang++ builds
nickpdemarco 51bdb9d
Remove errant read() from docs
nickpdemarco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Fields as underlying types | ||
|
|
||
| When you declare fields in a tuple or struct using `field name (offset = X, type = T);`, the generated C++ exposes helper wrapper types: | ||
|
|
||
| - `rust::FieldOwned<T, OFFSET>` for fields on owning types | ||
| - `rust::FieldRef<T, OFFSET>` for fields on `Ref<Ty>` | ||
| - `rust::FieldRefMut<T, OFFSET>` for fields on `RefMut<Ty>` | ||
|
|
||
| These wrappers now act as their underlying type `T` in many contexts: | ||
|
|
||
| - `Ref<T>` construction from any `Field*<T, OFFSET>` | ||
| - Implicit read via `operator T()` for value-like access | ||
| - Method calls are forwarded when applicable | ||
|
|
||
| Example: | ||
|
|
||
| ```C++ | ||
| rust::Tuple<int32_t, rust::std::string::String> t{42, "hi"_rs.to_owned()}; | ||
|
|
||
| // Read value | ||
| int32_t v = t.f0; // operator T() on FieldOwned<int32_t, 0> | ||
|
|
||
| // Get a Ref<T> from a field | ||
| rust::Ref<int32_t> r = t.f0; | ||
|
|
||
| // Access methods through Ref from Field wrappers | ||
| rust::Ref<rust::std::string::String> sref = t.f1; | ||
| auto len = sref.len(); | ||
|
|
||
| // From references to container, fields become FieldRef/FieldRefMut | ||
| rust::Ref<decltype(t)> rt = t; | ||
| auto l1 = rt.f1.len(); | ||
|
|
||
| rust::RefMut<decltype(t)> mt = t; | ||
| mt.f1.push_str("!"_rs); | ||
| ``` | ||
|
|
||
| See `examples/regression_test1` for a runnable demonstration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.