Skip to content

Commit 33ee9c7

Browse files
committed
wip: migrate examples
1 parent b04a3af commit 33ee9c7

19 files changed

Lines changed: 73 additions & 51 deletions

File tree

examples/conditional/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ int main() {
3131
s.push(KVPair{key.to_owned(), static_cast<KVPairValue_T>(value)});
3232
}
3333
auto it = s.iter();
34-
for (auto next = it.next(); next.matches_Some(); next = it.next()) {
35-
auto pair = next.unwrap();
34+
for (auto next = it.next(); auto some = Option<rust::Ref<KVPair>>::Some::match(next); next = it.next()) {
35+
rust::Ref<KVPair> pair = some->f0;
3636
rust::Ref<rust::std::string::String> key = pair.key;
3737
KVPairValue_T value = pair.value;
3838
std::cout << "KVPair(size = " << KVPair::self_size()

examples/conditional/main.zng

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,29 @@ mod ::std {
5151
type option::Option<usize> {
5252
#layout(size = 16, align = 8);
5353

54-
constructor None;
55-
constructor Some(usize);
56-
57-
fn unwrap(self) -> usize;
54+
variant None {}
55+
variant Some {
56+
field 0 (offset = auto, type = usize);
57+
}
5858
}
5959

6060
type option::Option<crate::KeyValuePair> {
6161
#layout(size = 32, align = 8);
6262

63-
constructor None;
64-
constructor Some(crate::KeyValuePair);
65-
66-
fn unwrap(self) -> crate::KeyValuePair;
63+
variant None {}
64+
variant Some {
65+
field 0 (offset = auto, type = crate::KeyValuePair);
66+
}
6767
}
6868

6969
type option::Option<&crate::KeyValuePair> {
7070
#layout(size = 8, align = 8);
7171
wellknown_traits(Copy);
7272

73-
constructor None;
74-
constructor Some(&crate::KeyValuePair);
75-
76-
fn unwrap(self) -> &crate::KeyValuePair;
73+
variant None {}
74+
variant Some {
75+
field 0 (offset = auto, type = &crate::KeyValuePair);
76+
}
7777
}
7878

7979

examples/memory_management/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ int main() {
119119
}
120120
std::cout << "Checkpoint 35" << std::endl;
121121
{
122-
auto p1 = Option<PrintOnDrop>::Some(
122+
Option<PrintOnDrop> p1 = Option<PrintOnDrop>::Some(
123123
PrintOnDrop("option_A"_rs));
124124
std::cout << "Checkpoint 36" << std::endl;
125-
auto p2 = Option<PrintOnDrop>::Some(
125+
Option<PrintOnDrop> p2 = Option<PrintOnDrop>::Some(
126126
PrintOnDrop("option_B"_rs));
127127
std::cout << "Checkpoint 37" << std::endl;
128128
p2.take();
@@ -135,7 +135,7 @@ int main() {
135135
rust::Ref<rust::Str> elems[3] = {"elem1"_rs, "elem2"_rs, "elem3"_rs};
136136
int i = 0;
137137
auto iter = rust::std::iter::from_fn(
138-
rust::Box<rust::Dyn<rust::Fn<Option<PrintOnDrop>>>>::make_box([&] {
138+
rust::Box<rust::Dyn<rust::Fn<Option<PrintOnDrop>>>>::make_box([&]() -> Option<PrintOnDrop> {
139139
if (i == 3) {
140140
return Option<PrintOnDrop>::None();
141141
}

examples/memory_management/main.zng

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ mod ::std {
7171
type Option<crate::PrintOnDrop> {
7272
#layout(size = 16, align = 8);
7373

74-
constructor Some(crate::PrintOnDrop);
75-
constructor None;
74+
variant None {}
75+
variant Some {
76+
field 0 (offset = auto, type = crate::PrintOnDrop);
77+
}
7678

7779
fn take(&mut self) -> Option<crate::PrintOnDrop>;
7880
}

examples/multiple_modules/processor/processor.zng

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ type crate::Processor {
1212
type ::std::option::Option<crate::Processor> {
1313
#layout(size = 1, align = 1);
1414

15-
constructor None;
16-
constructor Some(crate::Processor);
17-
fn unwrap(self) -> crate::Processor;
15+
variant None {}
16+
variant Some {
17+
field 0 (offset = auto, type = crate::Processor);
18+
}
19+
fn unwrap(self) -> crate::Processor;
1820
}

examples/multiple_modules/receiver/receiver.zng

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ type crate::Receiver {
1111
type ::std::option::Option<crate::Receiver> {
1212
#layout(size = 16, align = 8);
1313

14-
constructor None;
15-
constructor Some(crate::Receiver);
16-
fn unwrap(self) -> crate::Receiver;
14+
variant None {}
15+
variant Some {
16+
field 0 (offset = auto, type = crate::Receiver);
17+
}
18+
fn unwrap(self) -> crate::Receiver;
1719
}

examples/regression_test2/main.zng

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ type crate::Dispatcher {
1212

1313
type ::core::task::Poll<()> {
1414
#layout(size = 1, align = 1);
15-
constructor Ready(());
16-
constructor Pending;
15+
variant Ready { non_exhaustive; }
16+
variant Pending {}
1717

1818
fn is_ready(&self) -> bool;
1919
fn is_pending(&self) -> bool;

examples/rustyline/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ int main() {
1414
auto r = editor.readline(">>> "_rs);
1515
if (r.is_err()) {
1616
auto e = r.unwrap_err();
17-
if (e.matches_Eof()) {
17+
if (rust::rustyline::error::ReadlineError::Eof::check(e)) {
1818
std::cout << "CTRL-D" << std::endl;
1919
}
20-
if (e.matches_Interrupted()) {
20+
if (rust::rustyline::error::ReadlineError::Interrupted::check(e)) {
2121
std::cout << "CTRL-C" << std::endl;
2222
}
2323
break;

examples/rustyline/main.zng

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ mod ::rustyline {
3535

3636
type error::ReadlineError {
3737
#heap_allocated;
38+
non_exhaustive;
3839

39-
constructor Interrupted;
40-
constructor Eof;
40+
variant Interrupted {}
41+
variant Eof {}
4142
}
4243

4344
type Result<DefaultEditor> {

examples/simple/expected_output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
17
22
s[2] = 7
33

4-
thread panicked at examples/simple/src/generated.rs:351:40:
4+
thread panicked at examples/simple/src/generated.rs:375:40:
55
called `Option::unwrap()` on a `None` value
66
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
77
s[4] = Rust panic happened

0 commit comments

Comments
 (0)