1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct DatasetColumn {
    /// The order that the column comes in, 0-based. (The first column is 0,
    /// second is 1, etc.)
    order: Option<f32>,
    /// The column name
    name: Option<String>,
    /// The type of all of the fields in the column. Please see the data types on https://github.com/Kaggle/kaggle-api/wiki/Dataset-Metadata
    #[serde(rename = "type")]
    field_type: Option<String>,
    /// Used to store the original type of the column, which will be converted
    /// to Kaggle's types. For example, an `originalType` of `\"integer\"` would
    /// convert to a `type` of `\"numeric\"`
    #[serde(rename = "originalType")]
    original_type: Option<String>,
    /// The description of the column
    description: Option<String>,
}

impl DatasetColumn {
    pub fn new(name: impl ToString) -> Self {
        Self {
            name: Some(name.to_string()),
            ..Default::default()
        }
    }

    pub fn set_order(&mut self, order: f32) {
        self.order = Some(order);
    }

    pub fn with_order(mut self, order: f32) -> DatasetColumn {
        self.order = Some(order);
        self
    }

    pub fn order(&self) -> Option<&f32> {
        self.order.as_ref()
    }

    pub fn reset_order(&mut self) {
        self.order = None;
    }

    pub fn set_name(&mut self, name: String) {
        self.name = Some(name);
    }

    pub fn with_name(mut self, name: String) -> DatasetColumn {
        self.name = Some(name);
        self
    }

    pub fn name(&self) -> Option<&String> {
        self.name.as_ref()
    }

    pub fn reset_name(&mut self) {
        self.name = None;
    }

    pub fn set_type(&mut self, _type: String) {
        self.field_type = Some(_type);
    }

    pub fn with_type(mut self, _type: String) -> DatasetColumn {
        self.field_type = Some(_type);
        self
    }

    pub fn get_type(&self) -> Option<&String> {
        self.field_type.as_ref()
    }

    pub fn reset_type(&mut self) {
        self.field_type = None;
    }

    pub fn set_original_type(&mut self, original_type: String) {
        self.original_type = Some(original_type);
    }

    pub fn with_original_type(mut self, original_type: String) -> DatasetColumn {
        self.original_type = Some(original_type);
        self
    }

    pub fn original_type(&self) -> Option<&String> {
        self.original_type.as_ref()
    }

    pub fn reset_original_type(&mut self) {
        self.original_type = None;
    }

    pub fn set_description(&mut self, description: String) {
        self.description = Some(description);
    }

    pub fn with_description(mut self, description: String) -> DatasetColumn {
        self.description = Some(description);
        self
    }

    pub fn description(&self) -> Option<&String> {
        self.description.as_ref()
    }

    pub fn reset_description(&mut self) {
        self.description = None;
    }
}