Skip to content

Commit 36cfa7f

Browse files
committed
Remove read and as_ref methods on fields
1 parent dab8088 commit 36cfa7f

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

examples/regression_test1/expected_output.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ Test fields and constructor work -- finished
5151

5252
Test Field* underlying conversions -- started
5353
[main.cpp:70] v0 = 42
54-
[main.cpp:74] sref.len() = 2
55-
[main.cpp:77] pref.f0.read() = 42
56-
[main.cpp:78] pref.f1.len() = 2
57-
[main.cpp:81] pmut.f0.read() = 42
58-
[main.cpp:83] pmut.f1.len() = 3
54+
[main.cpp:76] sref.len() = 2
55+
[main.cpp:79] int32_t(pref.f0) = 42
56+
[main.cpp:80] pref.f1.len() = 2
57+
[main.cpp:83] int32_t(pmut.f0) = 42
58+
[main.cpp:85] pmut.f1.len() = 3
5959
Test Field* underlying conversions -- finished
6060

examples/regression_test1/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,22 @@ void test_field_underlying_conversions() {
6565
rust::Tuple<int32_t, rust::std::string::String> pair{42, "hi"_rs.to_owned()};
6666

6767
// FieldOwned conversion to Ref and value
68-
rust::Ref<int32_t> r0 = pair.f0; // Ref from FieldOwned
69-
int32_t v0 = pair.f0; // value read via operator T()
68+
rust::Ref<int32_t> r0 = pair.f0;
69+
int32_t v0 = pair.f0;
7070
zngur_dbg(v0);
71+
// TODO: Add support for conversion to T for all fields.
72+
// rust::std::string::String v1 = pair.f1;
7173

7274
// FieldOwned<String> to Ref<String> and call a method
7375
rust::Ref<rust::std::string::String> sref = pair.f1;
7476
zngur_dbg(sref.len());
7577

7678
rust::Ref<rust::Tuple<int32_t, rust::std::string::String>> pref = pair;
77-
zngur_dbg(pref.f0.read());
79+
zngur_dbg(int32_t(pref.f0));
7880
zngur_dbg(pref.f1.len());
7981

8082
rust::RefMut<rust::Tuple<int32_t, rust::std::string::String>> pmut = pair;
81-
zngur_dbg(pmut.f0.read());
83+
zngur_dbg(int32_t(pmut.f0));
8284
pmut.f1.push_str("!"_rs);
8385
zngur_dbg(pmut.f1.len());
8486
}

examples/regression_test1/main.zng

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ type crate::Scoped {
4444
#layout(size = 16, align = 8);
4545

4646
fn new(&str) -> crate::Scoped;
47-
}
47+
}

zngur-generator/src/cpp.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,23 +1659,17 @@ namespace rust {
16591659
16601660
template<typename T, size_t OFFSET>
16611661
struct FieldOwned {
1662-
inline ::rust::Ref<T> as_ref() const noexcept { return ::rust::Ref<T>(*this); }
1663-
inline T read() const noexcept { auto r = as_ref(); return *r; }
1664-
inline operator T() const noexcept { return read(); }
1662+
inline operator T() const noexcept { return *::rust::Ref<T>(*this); }
16651663
};
16661664
16671665
template<typename T, size_t OFFSET>
16681666
struct FieldRef {
1669-
inline ::rust::Ref<T> as_ref() const noexcept { return ::rust::Ref<T>(*this); }
1670-
inline T read() const noexcept { auto r = as_ref(); return *r; }
1671-
inline operator T() const noexcept { return read(); }
1667+
inline operator T() const noexcept { return *::rust::Ref<T>(*this); }
16721668
};
16731669
16741670
template<typename T, size_t OFFSET>
16751671
struct FieldRefMut {
1676-
inline ::rust::Ref<T> as_ref() const noexcept { return ::rust::Ref<T>(*this); }
1677-
inline T read() const noexcept { auto r = as_ref(); return *r; }
1678-
inline operator T() const noexcept { return read(); }
1672+
inline operator T() const noexcept { return *::rust::Ref<T>(*this); }
16791673
};
16801674
16811675
template<typename... T>

0 commit comments

Comments
 (0)