Skip to main content

datafusion_cli/
pool_type.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5use std::{
6    fmt::{self, Display, Formatter},
7    str::FromStr,
8};
9
10#[derive(PartialEq, Debug, Clone)]
11pub enum PoolType {
12    Greedy,
13    Fair,
14}
15
16impl FromStr for PoolType {
17    type Err = String;
18
19    fn from_str(s: &str) -> Result<Self, Self::Err> {
20        match s {
21            "Greedy" | "greedy" => Ok(PoolType::Greedy),
22            "Fair" | "fair" => Ok(PoolType::Fair),
23            _ => Err(format!("Invalid memory pool type '{s}'")),
24        }
25    }
26}
27
28impl Display for PoolType {
29    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
30        match self {
31            PoolType::Greedy => write!(f, "greedy"),
32            PoolType::Fair => write!(f, "fair"),
33        }
34    }
35}