Struct planus::Builder

source ·
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

source

pub fn new() -> Self

Creates a new Builder.

source

pub fn len(&self) -> usize

Gets the length of the internal buffer in bytes.

source

pub fn is_empty(&self) -> bool

Returns true if the internal buffer is empty.

source

pub fn with_capacity(capacity: usize) -> Self

Creates a new builder with a specific internal capacity already allocated.

source

pub fn clear(&mut self)

Resets the builders internal state and clears the internal buffer.

source

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§

source§

impl Debug for Builder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Builder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.