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: chunked_utils.rs
    path of file: ./repos/qdrant/lib/segment/src/vector_storage
    
    the code of the file until where you have to start completion: use std::collections::HashMap;
use std::path::{Path, PathBuf};

use memory::mmap_ops::{create_and_ensure_length, open_write_mmap};

use crate::common::mmap_type::MmapSlice;
use crate::common::operation_error::{OperationError, OperationResult};
use crate::data_types::vectors::VectorElementType;

const MMAP_CHUNKS_PATTERN_START: &str = "chunk_";
const MMAP_CHUNKS_PATTERN_END: &str = ".mmap";

/// Memory mapped chunk data.
pub type MmapChunk = MmapSlice<VectorElementType>;

/// Checks if the file name matches the pattern for mmap chunks
/// Return ID from the file name if it matches, None otherwise
fn check_mmap_file_name_pattern(file_name: &str) -> Option<usize> {
    file_name
        .strip_prefix(MMAP_CHUNKS_PATTERN_START)
        .and_then(|file_name| file_name.strip_suffix(MMAP_CHUNKS_PATTERN_END))
        .and_then(|file_name| file_name.parse::<usize>().ok
    
pub fn read_mmaps(directory: &Path) -> OperationResult<Vec<MmapChunk>> {
    let mut mmap_files: HashMap<usize, _> = HashMap::new();
    for entry in directory.read_dir()? {
        let entry = entry?;
        let path = entry.path();
        if path.is_file() {
            let chunk_id = path
                .file_name()
                .and_then(|file_name| file_name.to_str())
                .and_then(check_mmap_file_name_pattern);

            if let Some(chunk_id) = chunk_id {
                mmap_files.insert(chunk_id, path);
            }
        }
    }

    let num_chunks = mmap_files.len();
    let mut result = Vec::with_capacity(num_chunks);
    for chunk_id in 0..num_chunks {
        let mmap_file = mmap_files.remove(&chunk_id).ok_or_else(|| {
            OperationError::service_error(format!(
                "Missing mmap chunk {chunk_id} in {}",
                directory.display(),
            ))
        })?;
        let mmap = open_write_mmap(&mmap_file)?;
        let chunk = unsafe { MmapChunk::try_from(mmap)? };
        result.push(chunk);
    }
    Ok(result)
}