Skip to content
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

Rust: Render doc comments on types #189

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/xdrgen/generators/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,14 @@ def render_source_comment(out, defn)
return if defn.is_a?(AST::Definitions::Namespace)

out.puts <<-EOS.strip_heredoc
// #{name defn} is an XDR #{defn.class.name.demodulize} defines as:
//
/// #{name defn} is an XDR #{defn.class.name.demodulize} defines as:
///
EOS

out.puts "// " + defn.text_value.split("\n").join("\n// ")
out.puts "/// " + defn.text_value.split("\n").join("\n// ")

out.puts <<-EOS.strip_heredoc
//
///
EOS
end

Expand Down
8 changes: 4 additions & 4 deletions spec/output/generator_spec_rust/block_comments.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,13 +2686,13 @@ mod test {
}
}

// AccountFlags is an XDR Enum defines as:
//
// enum AccountFlags
/// AccountFlags is an XDR Enum defines as:
///
/// enum AccountFlags
// { // masks for each flag
// AUTH_REQUIRED_FLAG = 0x1
// };
//
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down
24 changes: 12 additions & 12 deletions spec/output/generator_spec_rust/const.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,22 +2686,22 @@ mod test {
}
}

// Foo is an XDR Const defines as:
//
// const FOO = 1;
//
/// Foo is an XDR Const defines as:
///
/// const FOO = 1;
///
pub const FOO: u64 = 1;

// TestArray is an XDR Typedef defines as:
//
// typedef int TestArray[FOO];
//
/// TestArray is an XDR Typedef defines as:
///
/// typedef int TestArray[FOO];
///
pub type TestArray = [i32; Foo];

// TestArray2 is an XDR Typedef defines as:
//
// typedef int TestArray2<FOO>;
//
/// TestArray2 is an XDR Typedef defines as:
///
/// typedef int TestArray2<FOO>;
///
pub type TestArray2 = VecM::<i32, 1>;

#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down
24 changes: 12 additions & 12 deletions spec/output/generator_spec_rust/enum.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,9 +2686,9 @@ mod test {
}
}

// MessageType is an XDR Enum defines as:
//
// enum MessageType
/// MessageType is an XDR Enum defines as:
///
/// enum MessageType
// {
// ERROR_MSG,
// HELLO,
Expand All @@ -2711,7 +2711,7 @@ mod test {
// FBA_QUORUMSET,
// FBA_MESSAGE
// };
//
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down Expand Up @@ -2865,14 +2865,14 @@ Self::FbaMessage => "FbaMessage",
}
}

// Color is an XDR Enum defines as:
//
// enum Color {
/// Color is an XDR Enum defines as:
///
/// enum Color {
// RED=0,
// GREEN=1,
// BLUE=2
// };
//
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down Expand Up @@ -2971,14 +2971,14 @@ Self::Blue => "Blue",
}
}

// Color2 is an XDR Enum defines as:
//
// enum Color2 {
/// Color2 is an XDR Enum defines as:
///
/// enum Color2 {
// RED2=RED,
// GREEN2=1,
// BLUE2=2
// };
//
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down
40 changes: 20 additions & 20 deletions spec/output/generator_spec_rust/nesting.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,14 +2686,14 @@ mod test {
}
}

// UnionKey is an XDR Enum defines as:
//
// enum UnionKey {
/// UnionKey is an XDR Enum defines as:
///
/// enum UnionKey {
// ONE = 1,
// TWO = 2,
// OFFER = 3
// };
//
///
// enum
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down Expand Up @@ -2792,18 +2792,18 @@ Self::Offer => "Offer",
}
}

// Foo is an XDR Typedef defines as:
//
// typedef int Foo;
//
/// Foo is an XDR Typedef defines as:
///
/// typedef int Foo;
///
pub type Foo = i32;

// MyUnionOne is an XDR NestedStruct defines as:
//
// struct {
/// MyUnionOne is an XDR NestedStruct defines as:
///
/// struct {
// int someInt;
// }
//
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(all(feature = "serde", feature = "alloc"), derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case"))]
Expand Down Expand Up @@ -2832,13 +2832,13 @@ impl WriteXdr for MyUnionOne {
}
}

// MyUnionTwo is an XDR NestedStruct defines as:
//
// struct {
/// MyUnionTwo is an XDR NestedStruct defines as:
///
/// struct {
// int someInt;
// Foo foo;
// }
//
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(all(feature = "serde", feature = "alloc"), derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case"))]
Expand Down Expand Up @@ -2870,9 +2870,9 @@ self.foo.write_xdr(w)?;
}
}

// MyUnion is an XDR Union defines as:
//
// union MyUnion switch (UnionKey type)
/// MyUnion is an XDR Union defines as:
///
/// union MyUnion switch (UnionKey type)
// {
// case ONE:
// struct {
Expand All @@ -2888,7 +2888,7 @@ self.foo.write_xdr(w)?;
// case OFFER:
// void;
// };
//
///
// union with discriminant UnionKey
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
Expand Down
16 changes: 8 additions & 8 deletions spec/output/generator_spec_rust/optional.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,21 +2686,21 @@ mod test {
}
}

// Arr is an XDR Typedef defines as:
//
// typedef int Arr[2];
//
/// Arr is an XDR Typedef defines as:
///
/// typedef int Arr[2];
///
pub type Arr = [i32; 2];

// HasOptions is an XDR Struct defines as:
//
// struct HasOptions
/// HasOptions is an XDR Struct defines as:
///
/// struct HasOptions
// {
// int* firstOption;
// int *secondOption;
// Arr *thirdOption;
// };
//
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(all(feature = "serde", feature = "alloc"), derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case"))]
Expand Down
16 changes: 8 additions & 8 deletions spec/output/generator_spec_rust/struct.x/MyXDR.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,23 +2686,23 @@ mod test {
}
}

// Int64 is an XDR Typedef defines as:
//
// typedef hyper int64;
//
/// Int64 is an XDR Typedef defines as:
///
/// typedef hyper int64;
///
pub type Int64 = i64;

// MyStruct is an XDR Struct defines as:
//
// struct MyStruct
/// MyStruct is an XDR Struct defines as:
///
/// struct MyStruct
// {
// int someInt;
// int64 aBigInt;
// opaque someOpaque[10];
// string someString<>;
// string maxString<100>;
// };
//
///
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[cfg_attr(all(feature = "serde", feature = "alloc"), derive(serde::Serialize, serde::Deserialize), serde(rename_all = "snake_case"))]
Expand Down
Loading
Loading