[][src]Struct foundationdb::api::NetworkBuilder

pub struct NetworkBuilder { /* fields omitted */ }

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

impl NetworkBuilder[src]

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

Set network options.

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

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");

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

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

impl RefUnwindSafe for NetworkBuilder

impl Send for NetworkBuilder

impl Sync for NetworkBuilder

impl Unpin for NetworkBuilder

impl UnwindSafe for NetworkBuilder

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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