You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: actor.rs
    path of file: ./repos/nox/aquamarine/src
    
    the code of the file until where you have to start completion: /*
 * Copyright 2020 Fluence Labs Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

use futures::future::BoxFuture;
use futures::FutureExt;
use std::sync::Arc;
use std::{
    collections::VecDeque,
    task::{Context, Poll, Waker},
};
use tracing::{instrument, Instrument, Span};

use crate::deadline::Deadline;
use crate::particle_effects::RawRoutingEffects;
use crate::particle_executor::{FutResult, ParticleExecutor};
use crate::particle_functions::{Functions, SingleCallStat};
use crate::spawner::{SpawnFunctions, Spawner};
use crate::{AquaRuntime, InterpretationS
    
    pub fn poll_next(&mut self, vm_id: usize, vm: RT, cx: &mut Context<'_>) -> ActorPoll<RT> {
        self.waker = Some(cx.waker().clone());

        self.functions.poll(cx);

        // Return vm if previous particle is still executing
        if self.is_executing() {
            return ActorPoll::Vm(vm_id, vm);
        }

        // Gather CallResults
        let (calls, stats, call_spans) = self.functions.drain();

        // Take the next particle
        let ext_particle = self.mailbox.pop_front();

        if ext_particle.is_none() && calls.is_empty() {
            debug_assert!(stats.is_empty(), "stats must be empty if calls are empty");
            // Nothing to execute, return vm
            return ActorPoll::Vm(vm_id, vm);
        }

        let particle = ext_particle
            .as_ref()
            .map(|p| p.particle.clone())
            .unwrap_or_else(|| {
                // If mailbox is empty, then take self.particle.
                // Its data is empty, so `vm` will process `calls` on the old (saved on disk) data
                self.particle.clone()
            });

        let waker = cx.waker().clone();
        let data_store = self.data_store.clone();
        let key_pair = self.key_pair.clone();
        let peer_id = self.current_peer_id;

        let (async_span, linking_span) =
            self.create_spans(call_spans, ext_particle, particle.id.as_str());

        let spawner = self.spawner.clone();
        self.future = Some(
            self.spawner
                .wrap(async move {
                    let res = vm
                        .execute(
                            spawner,
                            data_store,
                            (particle.clone(), calls),
                            peer_id,
                            key_pair,
                        )
                        .in_current_span()
                        .await;

                    waker.wake();

                    let reusables = Reusables {
                        vm_id,
                        vm: res.runtime,
                    };

                    (reusables, res.effects, res.stats, linking_span)
                })
                .instrument(async_span)
                .boxed(),
        );
        self.wake();

        ActorPoll::Executing(stats)
    }