有点类似

#[derive(Debug)]
pub struct Rectangle {
    length: u32,
    width: u32,
}

impl Rectangle {
    pub fn can_hold(&self, other: &Rectangle) -> bool {
    self.length > other.length && self.width > other.width
    }
}

pub fn add_two(a: i32) -> i32 {
    a +
}

pub fn greeting(name: &str) -> String {
    format!("Hello {}!", name)
}

pub struct Guess {
    value: i32,
}

impl Guess {
    pub fn new(value: i32) -> Guess {
     {
        panic!("Guess value must be great than or equal 1, got {}.", value);
    }  {
        panic!("Guess value must less than or equal to 100, got {}.", value);
    }

    Guess {
        value
    }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn larger_can_hold_smaller() {
    let larger = Rectangle { length: , width:  };
    let smaller = Rectangle { length: , width:  };
    assert!(larger.can_hold(&smaller));
    }

    #[test]
    fn smaller_cannot_hold_larger() {
    let larger = Rectangle { length: , width:  };
        let smaller = Rectangle { length: , width:  };
        assert!(!smaller.can_hold(&larger));
    }

    #[test]
    fn it_add_two() {
    assert_eq!(, add_two());
    }

    #[test]
    fn greeting_contains_name() {
    let result = greeting("Carol");
     assert!(result.contains("Carol"));
    }

    #[test]
    #[should_panic(expected = "Guess value must be less than or equal to 100")]
    fn greater_than_100() {
    Guess::);
    }

    /*
    #[test]
    fn it_works() -> Result<(), String> {
    if 2 + 2 == 4 {
        Ok(())
    } else {
        Err(String::from("two plus two does not equal four"))
       }
    }
    */
}

最新文章

  1. CSS 后代选择器
  2. 解析for循环
  3. 解决在使用client object model的时候报“object does not belong to a list”错误
  4. UVA 10294 等价类计数
  5. 保存恢复临时信-Android 中使用onSaveInstanceState和onRestoreInstanceState
  6. hibernate注解@JoinTable说明
  7. 经典sql总结(2)
  8. AS3 IOC框架Spring Actionscript 的使用总结
  9. insert into select 堵塞update
  10. sql server数据库区分大小写设置
  11. iOS实践03
  12. Bootstrap3 栅格系统-实例:手机、平板、桌面
  13. QThread的一些使用心得
  14. jquery.validate.js的简单示例
  15. ELK部署与使用总结
  16. [APM] 2个实例+5个维度解读APM技术
  17. &lt;Yarn&gt; &lt;Capacity Scheduler&gt; &lt;Source Code&gt;
  18. 14. Longest Common Prefix (截取字符串)
  19. 【嵌入式】——arm裸机开发 step by step 之 按键控制 LED 和 蜂鸣器
  20. Python高手之路【七】python基础之模块

热门文章

  1. aiomysql
  2. table表格属性
  3. Python实现网络图形化界面多人聊天室 - Windows
  4. P2186 小Z的函数栈
  5. ubuntu中安装rabbitmq服务并成功启动
  6. Flutter命令突然无响应、vscode突然无法连接到IOS模拟器
  7. Pytest 使用简介
  8. Tsung 安装
  9. IIS锁定是默认设置的 (overrideModeDefault=&quot;Deny&quot;)问题解决
  10. SQL Server 通过“with as”方法查询树型结构