rust 建造者模式


#[derive(Debug,Serialize,Deserialize,Default)]
pub struct TableInfo{
    sheet_name:String,
    table_token:String,
    sheet_title:String,
}


impl TableInfo {
    #[warn(non_snake_case)]
    #[allow(dead_code)]
    pub fn new() -> Self{
        TableInfo{
            ..Default::default()
        }
    } 

    #[allow(dead_code)]
    pub fn set_name(mut self, sheet_name:&str) -> Self{
        self.sheet_name = sheet_name.to_string();
        self
    }

    #[warn(non_snake_case)]
    #[allow(dead_code)]
    pub fn set_table_token(mut self, table_token:&str) -> Self{
        self.table_token = table_token.to_string();
        self
    }

    #[warn(non_snake_case)]
    #[allow(dead_code)]
    pub fn sheet_title(mut self, sheet_title:&str) -> Self{
        self.sheet_title = sheet_title.to_string();
        self
    }

    #[allow(dead_code)]
    pub fn build(self) -> Self{
        self
    }
}

上一篇:Salesforce入门教程(中文)-002


下一篇:Git检查现有 SSH 密钥