Skip to content

Commit

Permalink
Include source_code_info in example file descriptors in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhickman committed Oct 28, 2023
1 parent daf08f9 commit 54302a2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
25 changes: 12 additions & 13 deletions protox-parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod tests;

const MAX_MESSAGE_FIELD_NUMBER: i32 = 536_870_911;

/// Parses a single protobuf source file into a [`FileDescriptorProto`](prost_types::FileDescriptorProto).
/// Parses a single protobuf source file into a [`FileDescriptorProto`].
///
/// This function only looks at the syntax of the file, without resolving type names or reading
/// imported files.
Expand Down Expand Up @@ -58,18 +58,17 @@ const MAX_MESSAGE_FIELD_NUMBER: i32 = 536_870_911;
/// ..Default::default()
/// }],
/// source_code_info: Some(SourceCodeInfo {
/// /* ... */
/// # location: vec![
/// # Location { path: vec![], span: vec![1, 4, 6, 5], ..Default::default() },
/// # Location { path: vec![3, 0], span: vec![2, 4, 23], ..Default::default() },
/// # Location { path: vec![4, 0], span: vec![4, 4, 6, 5], ..Default::default() },
/// # Location { path: vec![4, 0, 1], span: vec![4, 12, 15], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0], span: vec![5, 8, 20], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0, 1], span: vec![5, 12, 15], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0, 3], span: vec![5, 18, 19], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0, 6], span: vec![5, 8, 11], ..Default::default() },
/// # Location { path: vec![12], span: vec![1, 4, 22], ..Default::default() },
/// # ],
/// location: vec![
/// Location { path: vec![], span: vec![1, 4, 6, 5], ..Default::default() },
/// Location { path: vec![3, 0], span: vec![2, 4, 23], ..Default::default() },
/// Location { path: vec![4, 0], span: vec![4, 4, 6, 5], ..Default::default() },
/// Location { path: vec![4, 0, 1], span: vec![4, 12, 15], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0], span: vec![5, 8, 20], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0, 1], span: vec![5, 12, 15], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0, 3], span: vec![5, 18, 19], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0, 6], span: vec![5, 8, 11], ..Default::default() },
/// Location { path: vec![12], span: vec![1, 4, 22], ..Default::default() },
/// ],
/// }),
/// ..Default::default()
/// })
Expand Down
18 changes: 8 additions & 10 deletions protox/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ impl File {
/// }],
/// source_code_info: Some(SourceCodeInfo {
/// location: vec![
/// /* ... */
/// # Location { path: vec![], span: vec![0, 0, 15], ..Default::default() },
/// # Location { path: vec![4, 0], span: vec![0, 0, 15], ..Default::default() },
/// # Location { path: vec![4, 0, 1], span: vec![0, 8, 11], ..Default::default() }
/// Location { path: vec![], span: vec![0, 0, 15], ..Default::default() },
/// Location { path: vec![4, 0], span: vec![0, 0, 15], ..Default::default() },
/// Location { path: vec![4, 0, 1], span: vec![0, 8, 11], ..Default::default() }
/// ]
/// }),
/// ..Default::default()
Expand Down Expand Up @@ -179,10 +178,9 @@ impl File {
/// }],
/// source_code_info: Some(SourceCodeInfo {
/// location: vec![
/// /* ... */
/// # Location { path: vec![], span: vec![0, 0, 15], ..Default::default() },
/// # Location { path: vec![4, 0], span: vec![0, 0, 15], ..Default::default() },
/// # Location { path: vec![4, 0, 1], span: vec![0, 8, 11], ..Default::default() }
/// Location { path: vec![], span: vec![0, 0, 15], ..Default::default() },
/// Location { path: vec![4, 0], span: vec![0, 0, 15], ..Default::default() },
/// Location { path: vec![4, 0, 1], span: vec![0, 8, 11], ..Default::default() }
/// ]
/// }),
/// ..Default::default()
Expand All @@ -199,7 +197,7 @@ impl File {
})
}

/// Create a new instance of [`File`] from a parsed [`FileDescriptorProto`](prost_types::FileDescriptorProto).
/// Create a new instance of [`File`] from a parsed [`FileDescriptorProto`].
///
/// The file does not need to have type names or imports resolved. Typically, it would be returned by the [`parse()`](protox_parse::parse()) method.
pub fn from_file_descriptor_proto(file: prost_types::FileDescriptorProto) -> Self {
Expand All @@ -211,7 +209,7 @@ impl File {
}
}

/// Create an instance of [`File`] by deserializing a [`FileDescriptorProto`](prost_types::FileDescriptorProto)
/// Create an instance of [`File`] by deserializing a [`FileDescriptorProto`]
/// from the given bytes.
///
/// Unlike when going through [`from_file_descriptor_proto()`](File::from_file_descriptor_proto), extension options are preserved.
Expand Down
34 changes: 16 additions & 18 deletions protox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ pub use self::error::Error;
/// ..Default::default()
/// }],
/// source_code_info: Some(SourceCodeInfo {
/// /* ... */
/// # location: vec![
/// # Location { path: vec![], span: vec![1, 4, 19], ..Default::default() },
/// # Location { path: vec![4, 0], span: vec![1, 4, 19], ..Default::default() },
/// # Location { path: vec![4, 0, 1], span: vec![1, 12, 15], ..Default::default() },
/// # ],
/// location: vec![
/// Location { path: vec![], span: vec![1, 4, 19], ..Default::default() },
/// Location { path: vec![4, 0], span: vec![1, 4, 19], ..Default::default() },
/// Location { path: vec![4, 0, 1], span: vec![1, 12, 15], ..Default::default() },
/// ],
/// }),
/// ..Default::default()
/// },
Expand All @@ -110,18 +109,17 @@ pub use self::error::Error;
/// ..Default::default()
/// }],
/// source_code_info: Some(SourceCodeInfo {
/// /* ... */
/// # location: vec![
/// # Location { path: vec![], span: vec![1, 4, 5, 5], ..Default::default() },
/// # Location { path: vec![3, 0], span: vec![1, 4, 23], ..Default::default() },
/// # Location { path: vec![4, 0], span: vec![3, 4, 5, 5], ..Default::default() },
/// # Location { path: vec![4, 0, 1], span: vec![3, 12, 15], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0], span: vec![4, 8, 29], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0, 1], span: vec![4, 21, 24], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0, 3], span: vec![4, 27, 28], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0, 4], span: vec![4, 8, 16], ..Default::default() },
/// # Location { path: vec![4, 0, 2, 0, 6], span: vec![4, 17, 20], ..Default::default() },
/// # ],
/// location: vec![
/// Location { path: vec![], span: vec![1, 4, 5, 5], ..Default::default() },
/// Location { path: vec![3, 0], span: vec![1, 4, 23], ..Default::default() },
/// Location { path: vec![4, 0], span: vec![3, 4, 5, 5], ..Default::default() },
/// Location { path: vec![4, 0, 1], span: vec![3, 12, 15], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0], span: vec![4, 8, 29], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0, 1], span: vec![4, 21, 24], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0, 3], span: vec![4, 27, 28], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0, 4], span: vec![4, 8, 16], ..Default::default() },
/// Location { path: vec![4, 0, 2, 0, 6], span: vec![4, 17, 20], ..Default::default() },
/// ],
/// }),
/// ..Default::default()
/// },
Expand Down

0 comments on commit 54302a2

Please sign in to comment.