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: lib.rs
    path of file: ./repos/Ambient/crates/rpc/src
    
    the code of the file until where you have to start completion: use std::{
    collections::HashMap,
    io::{BufRead, Cursor, Write},
    sync::Arc,
};

use futures::{future::BoxFuture, Future, FutureExt};
use serde::{de::DeserializeOwned, Serialize};
use thiserror::Error;

#[allow(clippy::type_complexity)]
#[derive(Clone)]
pub struct RpcRegistry<Args> {
    registry: HashMap<
        String,
        Arc<dyn Fn(Args, &[u8]) -> BoxFuture<Result<Vec<u8>, RpcError>> + Send + Sync>,
    >,
    
    pub async fn run_req(&self, args: Args, req: &[u8]) -> Result<Vec<u8>, RpcError> {
        let mut reader = Cursor::new(req);
        let mut name = String::new();
        reader.read_line(&mut name)?;
        if name.is_empty() {
            return Err(RpcError::IOError(std::io::ErrorKind::InvalidData.into()));
        }
        let name = name[0..(name.len() - 1)].to_string();
        match self.registry.get(&name) {
            Some(func) => {
                let buf = reader.get_ref();
                let pos = (reader.position() as usize).min(buf.len());
                func(args, &buf[pos..]).await
            }
            None => Err(RpcError::NoSuchFunction(name)),
        }
    }