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: rpc.rs
    path of file: ./repos/chiselstrike/server/src
    
    the code of the file until where you have to start completion: // SPDX-FileCopyrightText: Â© 2021 ChiselStrike <info@chiselstrike.com>

use crate::datastore::{MetaService, QueryEngine};
use crate::policies::PolicySystem;
use crate::proto::chisel_rpc_server::{ChiselRpc, ChiselRpcServer};
use crate::proto::{
    ApplyRequest, ApplyResponse, DeleteRequest, De
    
async fn apply(server: Arc<Server>, request: ApplyRequest) -> Result<ApplyResponse> {
    let version_id = validate_version_id(&request.version_id)?;
    let info = VersionInfo {
        name: request.app_name.clone(),
        tag: request.version_tag.clone(),
    };

    let modules = request
        .modules
        .iter()
        .map(|m| (m.url.clone(), m.code.clone()))
        .collect::<HashMap<_, _>>();
    let modules = Arc::new(modules);
    validate_modules(
        server.clone(),
        version_id.clone(),
        info.clone(),
        modules.clone(),
    )
    .await
    .context("The provided code does not seem to work")?;

    let result = {
        let mut type_systems = server.type_systems.lock().await;
        let type_system = type_systems
            .entry(version_id.clone())
            .or_insert_with(|| TypeSystem::new(server.builtin_types.clone(), version_id.clone()));

        // NOTE: there is a race condition, because we migrate the database to the new schema, while
        // there might be workers that still assume the old schema
        apply::apply(
            server.clone(),
            &request,
            type_system,
            version_id.clone(),
            &info,
            &modules,
        )
        .await?
    };

    let (ready_tx, ready_rx) = oneshot::channel();
    let init = VersionInit {
        version_id,
        info,
        server: server.clone(),
        modules,
        type_system: Arc::new(result.type_system),
        policy_system: Arc::new(result.policy_system),
        worker_count: server.opt.worker_threads,
        ready_tx,
        is_canary: false,
        policy_sources: result.policy_sources,
    };

    let (version, job_tx, mut version_task) = version::spawn(init).await?;
    wait_until_ready(&mut version_task, ready_rx)
        .await
        .context(
            "The version did not start up correcly, but the database has already been modified",
        )?;
    server.trunk.add_version(version, job_tx, version_task);

    // try to update the secrets, so that if the user edited `.env`, the updated version will see
    // the new secrets immediately (this is in particular importance for tests).
    //
    // if an error happens, let's just ignore it: the `refresh_secrets()` task, which is
    // responsible for periodic updating of the secrets, will show the error
    let _: Result<()> = server::update_secrets(&server).await;

    Ok(ApplyResponse {
        types: result.type_names_user_order,
        labels: result.labels,
        event_handlers: Vec::new(),
    })
}