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: series.rs
    path of file: ./repos/vector/tests/e2e/datadog/metrics
    
    the code of the file until where you have to start completion: use std::collections::BTreeMap;

#[allow(warnings, clippy::pedantic, clippy::nursery)]
mod ddmetric_proto {
    include!(concat!(env!("OUT_DIR"), "/datadog.agentpayload.rs"));
}

use ddmetric_proto::{
    metric_payload::{MetricSeries, MetricType},
    MetricPayload,
};
use tracing::info;
use vector::common::datadog::DatadogSeriesMetric;

use self::ddmetric_proto::metric_payload::{MetricPoint, Resource};

use super::*;

const SERIES_ENDPOINT_V1: &str = "/api/v1/series";
const SERIES_ENDPOINT_V2: &str = "/api/v2/series";

// unique identification of a Series
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
struct SeriesContext {
    metric_name: String,
    tags: Vec<String>,
    r#type: i32,
}

#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
struct TimeBucket(i64, i64);

fn get_time_bucket(point: &MetricPoint, interval: i64, metric_type: MetricType) -> TimeBucket {
    match metric_type {
        MetricType::Unspecified => panic!("received an unspecified metric type"),
        MetricType::Rate => TimeBucket(point.timestamp - interval, point.timestamp),
        
    
fn generate_series_intake(payloads: &[MetricPayload]) -> SeriesIntake {
    let mut intake = BTreeMap::new();

    payloads.iter().for_each(|payload| {
        payload.series.iter().for_each(|serie| {
            // filter out the metrics we don't care about (ones not generated by the client)
            if !serie.metric.starts_with("foo_metric") {
                return;
            }

            let ctx = SeriesContext {
                metric_name: serie.metric.clone(),
                tags: serie.tags.clone(),
                r#type: serie.r#type,
            };

            if !intake.contains_key(&ctx) {
                intake.insert(ctx.clone(), BTreeMap::new());
            }
            let entry: &mut BTreeMap<TimeBucket, Vec<f64>> = intake.get_mut(&ctx).unwrap();

            serie.points.iter().for_each(|point| {
                let tb = get_time_bucket(point, serie.interval, serie.r#type());
                if !entry.contains_key(&tb) {
                    entry.insert(tb.clone(), Vec::new());
                }
                entry.get_mut(&tb).unwrap().push(point.value);
            });
        });
    });

    intake
}