hyperlight-common 0.14.0

Hyperlight's components common to host and guest.
Documentation
// automatically generated by the FlatBuffers compiler, do not modify
// @generated
extern crate alloc;
extern crate flatbuffers;
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::cmp::Ordering;
use core::mem;

use self::flatbuffers::{EndianScalar, Follow};
use super::*;
pub enum FunctionCallResultOffset {}
#[derive(Copy, Clone, PartialEq)]

pub struct FunctionCallResult<'a> {
    pub _tab: flatbuffers::Table<'a>,
}

impl<'a> flatbuffers::Follow<'a> for FunctionCallResult<'a> {
    type Inner = FunctionCallResult<'a>;
    #[inline]
    unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
        Self {
            _tab: unsafe { flatbuffers::Table::new(buf, loc) },
        }
    }
}

impl<'a> FunctionCallResult<'a> {
    pub const VT_RESULT_TYPE: flatbuffers::VOffsetT = 4;
    pub const VT_RESULT: flatbuffers::VOffsetT = 6;

    #[inline]
    pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
        FunctionCallResult { _tab: table }
    }
    #[allow(unused_mut)]
    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
        args: &'args FunctionCallResultArgs,
    ) -> flatbuffers::WIPOffset<FunctionCallResult<'bldr>> {
        let mut builder = FunctionCallResultBuilder::new(_fbb);
        if let Some(x) = args.result {
            builder.add_result(x);
        }
        builder.add_result_type(args.result_type);
        builder.finish()
    }

    #[inline]
    pub fn result_type(&self) -> FunctionCallResultType {
        // Safety:
        // Created from valid Table for this object
        // which contains a valid value in this slot
        unsafe {
            self._tab
                .get::<FunctionCallResultType>(
                    FunctionCallResult::VT_RESULT_TYPE,
                    Some(FunctionCallResultType::NONE),
                )
                .unwrap()
        }
    }
    #[inline]
    pub fn result(&self) -> flatbuffers::Table<'a> {
        // Safety:
        // Created from valid Table for this object
        // which contains a valid value in this slot
        unsafe {
            self._tab
                .get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(
                    FunctionCallResult::VT_RESULT,
                    None,
                )
                .unwrap()
        }
    }
    #[inline]
    #[allow(non_snake_case)]
    pub fn result_as_return_value_box(&self) -> Option<ReturnValueBox<'a>> {
        if self.result_type() == FunctionCallResultType::ReturnValueBox {
            let u = self.result();
            // Safety:
            // Created from a valid Table for this object
            // Which contains a valid union in this slot
            Some(unsafe { ReturnValueBox::init_from_table(u) })
        } else {
            None
        }
    }

    #[inline]
    #[allow(non_snake_case)]
    pub fn result_as_guest_error(&self) -> Option<GuestError<'a>> {
        if self.result_type() == FunctionCallResultType::GuestError {
            let u = self.result();
            // Safety:
            // Created from a valid Table for this object
            // Which contains a valid union in this slot
            Some(unsafe { GuestError::init_from_table(u) })
        } else {
            None
        }
    }
}

impl flatbuffers::Verifiable for FunctionCallResult<'_> {
    #[inline]
    fn run_verifier(
        v: &mut flatbuffers::Verifier,
        pos: usize,
    ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
        use self::flatbuffers::Verifiable;
        v.visit_table(pos)?
            .visit_union::<FunctionCallResultType, _>(
                "result_type",
                Self::VT_RESULT_TYPE,
                "result",
                Self::VT_RESULT,
                true,
                |key, v, pos| match key {
                    FunctionCallResultType::ReturnValueBox => v
                        .verify_union_variant::<flatbuffers::ForwardsUOffset<ReturnValueBox>>(
                            "FunctionCallResultType::ReturnValueBox",
                            pos,
                        ),
                    FunctionCallResultType::GuestError => v
                        .verify_union_variant::<flatbuffers::ForwardsUOffset<GuestError>>(
                            "FunctionCallResultType::GuestError",
                            pos,
                        ),
                    _ => Ok(()),
                },
            )?
            .finish();
        Ok(())
    }
}
pub struct FunctionCallResultArgs {
    pub result_type: FunctionCallResultType,
    pub result: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
}
impl<'a> Default for FunctionCallResultArgs {
    #[inline]
    fn default() -> Self {
        FunctionCallResultArgs {
            result_type: FunctionCallResultType::NONE,
            result: None, // required field
        }
    }
}

pub struct FunctionCallResultBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
    fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
    start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
}
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> FunctionCallResultBuilder<'a, 'b, A> {
    #[inline]
    pub fn add_result_type(&mut self, result_type: FunctionCallResultType) {
        self.fbb_.push_slot::<FunctionCallResultType>(
            FunctionCallResult::VT_RESULT_TYPE,
            result_type,
            FunctionCallResultType::NONE,
        );
    }
    #[inline]
    pub fn add_result(&mut self, result: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
        self.fbb_
            .push_slot_always::<flatbuffers::WIPOffset<_>>(FunctionCallResult::VT_RESULT, result);
    }
    #[inline]
    pub fn new(
        _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
    ) -> FunctionCallResultBuilder<'a, 'b, A> {
        let start = _fbb.start_table();
        FunctionCallResultBuilder {
            fbb_: _fbb,
            start_: start,
        }
    }
    #[inline]
    pub fn finish(self) -> flatbuffers::WIPOffset<FunctionCallResult<'a>> {
        let o = self.fbb_.end_table(self.start_);
        self.fbb_
            .required(o, FunctionCallResult::VT_RESULT, "result");
        flatbuffers::WIPOffset::new(o.value())
    }
}

impl core::fmt::Debug for FunctionCallResult<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        let mut ds = f.debug_struct("FunctionCallResult");
        ds.field("result_type", &self.result_type());
        match self.result_type() {
            FunctionCallResultType::ReturnValueBox => {
                if let Some(x) = self.result_as_return_value_box() {
                    ds.field("result", &x)
                } else {
                    ds.field(
                        "result",
                        &"InvalidFlatbuffer: Union discriminant does not match value.",
                    )
                }
            }
            FunctionCallResultType::GuestError => {
                if let Some(x) = self.result_as_guest_error() {
                    ds.field("result", &x)
                } else {
                    ds.field(
                        "result",
                        &"InvalidFlatbuffer: Union discriminant does not match value.",
                    )
                }
            }
            _ => {
                let x: Option<()> = None;
                ds.field("result", &x)
            }
        };
        ds.finish()
    }
}