Struct ReceiveFuture

Source
pub struct ReceiveFuture<T> { /* private fields */ }
Expand description

Will contain a value of type T received via a non-blocking receive operation.

Implementations§

Source§

impl<T> ReceiveFuture<T>
where T: Equivalence,

Source

pub fn get(self) -> (T, Status)

Wait for the receive operation to finish and return the received data.

§Panics

Received an empty message

Examples found in repository?
examples/immediate.rs (line 57)
8fn main() {
9    let universe = mpi::initialize().unwrap();
10    let world = universe.world();
11
12    let x = std::f32::consts::PI;
13    let mut y: f32 = 0.0;
14
15    mpi::request::scope(|scope| {
16        let mut sreq = world.this_process().immediate_send(scope, &x);
17        let rreq = world.any_process().immediate_receive_into(scope, &mut y);
18        rreq.wait();
19        loop {
20            match sreq.test() {
21                Ok(_) => {
22                    break;
23                }
24                Err(req) => {
25                    sreq = req;
26                }
27            }
28        }
29    });
30    assert_eq!(x, y);
31
32    y = 0.0;
33    mpi::request::scope(|scope| {
34        let _rreq = WaitGuard::from(world.any_process().immediate_receive_into(scope, &mut y));
35        let _sreq = WaitGuard::from(world.this_process().immediate_ready_send(scope, &x));
36    });
37    assert_eq!(x, y);
38
39    assert!(world.any_process().immediate_probe().is_none());
40    assert!(world.any_process().immediate_matched_probe().is_none());
41
42    y = 0.0;
43    mpi::request::scope(|scope| {
44        let _sreq: WaitGuard<_> = world
45            .this_process()
46            .immediate_synchronous_send(scope, &x)
47            .into();
48        let preq = world.any_process().immediate_matched_probe();
49        assert!(preq.is_some());
50        let (msg, _) = preq.unwrap();
51        let _rreq: WaitGuard<_> = msg.immediate_matched_receive_into(scope, &mut y).into();
52    });
53    assert_eq!(x, y);
54
55    let future = world.any_process().immediate_receive();
56    world.this_process().send(&x);
57    let (msg, _) = future.get();
58    assert_eq!(x, msg);
59
60    let future = world.any_process().immediate_receive();
61    let res = future.r#try();
62    assert!(res.is_err());
63    let mut future = res.err().unwrap();
64    world.this_process().send(&x);
65    loop {
66        match future.r#try() {
67            Ok((msg, _)) => {
68                assert_eq!(x, msg);
69                break;
70            }
71            Err(f) => {
72                future = f;
73            }
74        }
75    }
76
77    mpi::request::scope(|scope| {
78        let sreq = world.this_process().immediate_send(scope, &x);
79        sreq.cancel();
80        sreq.wait();
81
82        let _sreq = CancelGuard::from(world.this_process().immediate_receive_into(scope, &mut y));
83    });
84}
Source

pub fn try(self) -> Result<(T, Status), Self>

Check whether the receive operation has finished.

If the operation has finished, the data received is returned. Otherwise the future itself is returned.

§Panics

Received an empty message

§Errors

Receive has not finished yet

Examples found in repository?
examples/immediate.rs (line 61)
8fn main() {
9    let universe = mpi::initialize().unwrap();
10    let world = universe.world();
11
12    let x = std::f32::consts::PI;
13    let mut y: f32 = 0.0;
14
15    mpi::request::scope(|scope| {
16        let mut sreq = world.this_process().immediate_send(scope, &x);
17        let rreq = world.any_process().immediate_receive_into(scope, &mut y);
18        rreq.wait();
19        loop {
20            match sreq.test() {
21                Ok(_) => {
22                    break;
23                }
24                Err(req) => {
25                    sreq = req;
26                }
27            }
28        }
29    });
30    assert_eq!(x, y);
31
32    y = 0.0;
33    mpi::request::scope(|scope| {
34        let _rreq = WaitGuard::from(world.any_process().immediate_receive_into(scope, &mut y));
35        let _sreq = WaitGuard::from(world.this_process().immediate_ready_send(scope, &x));
36    });
37    assert_eq!(x, y);
38
39    assert!(world.any_process().immediate_probe().is_none());
40    assert!(world.any_process().immediate_matched_probe().is_none());
41
42    y = 0.0;
43    mpi::request::scope(|scope| {
44        let _sreq: WaitGuard<_> = world
45            .this_process()
46            .immediate_synchronous_send(scope, &x)
47            .into();
48        let preq = world.any_process().immediate_matched_probe();
49        assert!(preq.is_some());
50        let (msg, _) = preq.unwrap();
51        let _rreq: WaitGuard<_> = msg.immediate_matched_receive_into(scope, &mut y).into();
52    });
53    assert_eq!(x, y);
54
55    let future = world.any_process().immediate_receive();
56    world.this_process().send(&x);
57    let (msg, _) = future.get();
58    assert_eq!(x, msg);
59
60    let future = world.any_process().immediate_receive();
61    let res = future.r#try();
62    assert!(res.is_err());
63    let mut future = res.err().unwrap();
64    world.this_process().send(&x);
65    loop {
66        match future.r#try() {
67            Ok((msg, _)) => {
68                assert_eq!(x, msg);
69                break;
70            }
71            Err(f) => {
72                future = f;
73            }
74        }
75    }
76
77    mpi::request::scope(|scope| {
78        let sreq = world.this_process().immediate_send(scope, &x);
79        sreq.cancel();
80        sreq.wait();
81
82        let _sreq = CancelGuard::from(world.this_process().immediate_receive_into(scope, &mut y));
83    });
84}

Auto Trait Implementations§

§

impl<T> Freeze for ReceiveFuture<T>

§

impl<T> !RefUnwindSafe for ReceiveFuture<T>

§

impl<T> !Send for ReceiveFuture<T>

§

impl<T> !Sync for ReceiveFuture<T>

§

impl<T> Unpin for ReceiveFuture<T>

§

impl<T> UnwindSafe for ReceiveFuture<T>
where T: RefUnwindSafe,

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<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
Source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

Source§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
Source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
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, Dst> ConvAsUtil<Dst> for T

Source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
Source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
Source§

impl<T> ConvUtil for T

Source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
Source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
Source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
Source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
Source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
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<Src> TryFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
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<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

Source§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
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.
Source§

impl<Src> ValueFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
Source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

Source§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.