Struct NetworkBuilder

Source
pub struct NetworkBuilder { /* private fields */ }
Expand description

A Builder with which the foundationDB network event loop can be created

The foundationDB Network event loop can only be run once.

use foundationdb::api::FdbApiBuilder;

let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
let guard = unsafe { network_builder.boot() };
// do some work with foundationDB
drop(guard);

Implementations§

Source§

impl NetworkBuilder

Source

pub fn set_option(self, option: NetworkOption) -> FdbResult<Self>

Set network options.

Source

pub fn build(self) -> FdbResult<(NetworkRunner, NetworkWait)>

Finalizes the initialization of the Network and returns a way to run/wait/stop the FoundationDB run loop.

It’s not recommended to use this method directly, you probably want the boot() method.

In order to start the network you have to:

  • call the unsafe NetworkRunner::run() method, most likely in a dedicated thread
  • wait for the thread to start NetworkWait::wait

In order for the sequence to be safe, you MUST as stated in the NetworkRunner::run() method ensure that NetworkStop::stop() is called before the process exit. Aborting the process is still safe.

§Example
use foundationdb::api::FdbApiBuilder;

let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
let (runner, cond) = network_builder.build().expect("fdb network runners");

let net_thread = std::thread::spawn(move || {
    unsafe { runner.run() }.expect("failed to run");
});

// Wait for the foundationDB network thread to start
let fdb_network = cond.wait();

// do some work with foundationDB, if a panic occur you still **MUST** catch it and call
// fdb_network.stop();

// You **MUST** call fdb_network.stop() before the process exit
fdb_network.stop().expect("failed to stop network");
net_thread.join().expect("failed to join fdb thread");
Source

pub unsafe fn boot(self) -> FdbResult<NetworkAutoStop>

Starts the FoundationDB run loop in a dedicated thread. This finish initializing the FoundationDB Client API and can only be called once per process.

§Returns

A NetworkAutoStop handle which must be dropped before the program exits.

§Safety

You MUST ensure drop is called on the returned object before the program exits. This is not required if the program is aborted.

This method used to be safe in version 0.4. But because drop on the returned object might not be called before the program exits, it was found unsafe.

§Panics

Panics if the dedicated thread cannot be spawned or the internal condition primitive is poisonned.

§Examples
use foundationdb::api::FdbApiBuilder;

let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
let network = unsafe { network_builder.boot() };
// do some interesting things with the API...
drop(network);
use foundationdb::api::FdbApiBuilder;

#[tokio::main]
async fn main() {
    let network_builder = FdbApiBuilder::default().build().expect("fdb api initialized");
    let network = unsafe { network_builder.boot() };
    // do some interesting things with the API...
    drop(network);
}

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>,

Source§

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>,

Source§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V