pub struct Builder { /* private fields */ }
Expand description
Builder for serializing flatbuffers.
§Examples
use planus::Builder;
use planus_example::monster_generated::my_game::sample::Weapon;
let mut builder = Builder::new();
let weapon = Weapon::create(&mut builder, "Axe", 24);
builder.finish(weapon, None);
Implementations§
source§impl Builder
impl Builder
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new builder with a specific internal capacity already allocated.
sourcepub fn finish<T>(
&mut self,
root: impl WriteAsOffset<T>,
file_identifier: Option<[u8; 4]>
) -> &[u8] ⓘ
pub fn finish<T>( &mut self, root: impl WriteAsOffset<T>, file_identifier: Option<[u8; 4]> ) -> &[u8] ⓘ
Finish writing the internal buffer and return a byte slice of it.
This will make sure all alignment requirements are fullfilled and that the file identifier has been written if specified.
§Examples
use planus::Builder;
use planus_example::monster_generated::my_game::sample::Weapon;
let mut builder = Builder::new();
let weapon = Weapon::create(&mut builder, "Axe", 24);
builder.finish(weapon, None);
It can also be used to directly serialize an owned flatbuffers struct
use planus::Builder;
use planus_example::monster_generated::my_game::sample::Weapon;
let mut builder = Builder::new();
let weapon = Weapon { name: Some("Sword".to_string()), damage: 12 };
let data = builder.finish(&weapon, None);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more