Struct fbinit::FacebookInit
source · pub struct FacebookInit { /* private fields */ }
Expand description
This type is a token that allows code to prove initFacebook has been called.
A function can require this proof by taking _fb: FacebookInit
as an
argument.
The basic assumption of initFacebook is that it happens at the very beginning of main before there are additional threads. It must be allowed to modify process-global state like env vars or gflags without the risk of undefined behavior from other code concurrently reading those things.
The preferred way to obtain a proof token is through a pair of attribute
macros exported by this crate. #\[fbinit::main\]
is placed on your main
function and will call initFacebook and provide the resulting proof:
#[fbinit::main]
fn main(fb: fbinit::FacebookInit) {
/* ... */
}
The proof argument is optional. If you don’t need it, this is fine too:
#[fbinit::main]
fn main() {
/* ... */
}
If main is async, the attribute behaves like `#[tokio::main].
#[fbinit::main]
async fn main(fb: fbinit::FacebookInit) {
yay().await;
}
async fn yay() {}
There is also #\[fbinit::test\]
which behaves like #\[test\]
or
#\[tokio::test\]
.
#[fbinit::test]
fn test_my_service(fb: fbinit::FacebookInit) {
/* ... */
}
#[fbinit::test]
async fn async_test(fb: fbinit::FacebookInit) {
/* ... */
}
Trait Implementations§
source§impl Arbitrary for FacebookInit
impl Arbitrary for FacebookInit
source§impl Clone for FacebookInit
impl Clone for FacebookInit
source§fn clone(&self) -> FacebookInit
fn clone(&self) -> FacebookInit
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more