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

fix/improve rust getting started build.rs example + add docstring to Record::serialize #362

Merged
merged 2 commits into from
Mar 5, 2025
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
16 changes: 16 additions & 0 deletions Runtime/Rust/src/serialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ pub trait Record<'raw>: SubRecord<'raw> {
}

/// Serialize this record. It is highly recommend to use a buffered writer.
///
/// # Example
///
/// ```rust
/// // For fixed-size types
/// let value: MyFixedSizeType = /* ... */;
/// let mut buf = Vec::with_capacity(MyFixedSizeType::SERIALIZED_SIZE);
/// let bytes_written = value.serialize(&mut buf).unwrap();
/// ```
/// ```rust
/// // For variable-size types
/// let value: MyVariableSizeType = /* ... */;
/// let size = value.serialized_size();
/// let mut buf = Vec::with_capacity(size);
/// let bytes_written = value.serialize(&mut buf).unwrap();
/// ```
#[inline(always)]
fn serialize<W: Write>(&self, dest: &mut W) -> SeResult<usize> {
Self::_serialize_chained(self, dest)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/docs/guide/getting-started-rust.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fn main() {
// download the bebop binary automatically and cache it into your target directory
// it will automatically download the same version as the package you installed
bebop::download_bebopc(
PathBuf::from("target").join("bebopc"),
std::path::PathBuf::from("target").join("bebopc"),
);
// build all `.bop` schemas in `schemas` dir and make a new module `generated` in `src` with all of them.
bebop::build_schema_dir("schemas", "src/generated");
bebop::build_schema_dir("schemas", "src/generated", &bebop::BuildConfig::default());
}
```

Expand Down
Loading