Getting started (Rust)
Package | Cargo Latest | Downloads |
---|---|---|
bebop | ||
bebop-tools |
There are two packages to be aware of, the Rust runtime bebop
and the compiler-helper bebop-tools
.
So to get started, add the bebop
package to your dependencies
and add bebop-tools
to your build-dependencies
if you plan to use a cargo build script for generating the Rust code. Next, add the necessary steps to your build script to build the schema, this is an example buildscript:
Right now bebop-tools
is pretty bare-bones as far as what it supports, but at least with auto-downloading it should help with automation—if not do it for you.
Now assuming you have the schema
To actually build the generated file run cargo build
and you should see src/generated/mystruct.rs
is created automatically. You may want to add the generated directory to your git ignore. Also be aware that any changes to files in generated will be wiped out on every single build. Or if you have an IDE that is constantly running in the background like I do, after any change you save…
Also src/generated/mod.rs
is generated automatically for you and will publicly declare all the schemas as modules.
In your code, you can now write something like this:
Pro-tip: Check out the owned
module which is generated behind a feature flag. If you enable bebop-owned-all
or the appropriate namespace flag (only if you generated with a namespace) you can then access versions of all Records which do not borrow the data but simply take ownership/clone the data. These can be useful if you want to use bebop types throughout your codebase and not just for serialization.
That should be enough to get you kick-started. Checkout the crate docs for the runtime here and pay extra close attention to the Record
trait which is the main bebop serialization definition.