Skip to main content

from_fn

Function from_fn 

Source
pub fn from_fn<P, F>(decide: F) -> FromFn<F>
where P: PeerId, F: Fn(&PeerRequest<P>) -> Decision + Send + Sync + 'static,
Expand description

Returns a policy that decides with the synchronous closure decide.

ยงExamples

use moq_ext_access::{
    Grant,
    policy::{self, PeerRequest, Rejection},
};

let policy = policy::from_fn(|request: &PeerRequest<String>| {
    if request.token() == Some("secret") {
        Ok(Grant::everything().into())
    } else {
        Err(Rejection::new("no valid token"))
    }
});