basic/comment #1075
Replies: 17 comments 4 replies
-
/// 我怎么受不了这个文档注释,是我太菜么,看着就像一堆行代码注释 |
Beta Was this translation helpful? Give feedback.
-
模块注释是对模块文件的注释,而不是对单个模块的注释,所以特别强调 说实在的rust这个oacjage crate module的概念有些矫情 文档中可以直接写测试用例倒是不错 |
Beta Was this translation helpful? Give feedback.
-
在综合例子中,既然使用了 use art::mix;
use art::PrimaryColor; |
Beta Was this translation helpful? Give feedback.
-
这章好像没什么人,大家都不喜欢写注释是吧 😅 |
Beta Was this translation helpful? Give feedback.
-
一个综合例子 这部分的src/lib.rs 直接复制内容是有问题,自动加了一些内容进粘贴板 |
Beta Was this translation helpful? Give feedback.
-
一个文档玩出花🌸来了,我受不了啊 |
Beta Was this translation helpful? Give feedback.
-
Rust注释的花样也真多。。 |
Beta Was this translation helpful? Give feedback.
-
连注释都这么花哨~~ |
Beta Was this translation helpful? Give feedback.
-
功能太强大了 |
Beta Was this translation helpful? Give feedback.
-
是在代码块```中使用# 开头的会被隐藏? |
Beta Was this translation helpful? Give feedback.
-
今后可能真的不需要写注释了,AI自动注释太牛了 |
Beta Was this translation helpful? Give feedback.
-
Rust的文档功能太强大了 |
Beta Was this translation helpful? Give feedback.
-
比 js 的 typedoc 和 jsdoc 强的太多了 |
Beta Was this translation helpful? Give feedback.
-
我一直对 lib.rs 和 main.rs 之间的关系很糊涂. 为啥在 lib.rs 中声明 mod, main.rs 使用是不需要用 lib.rs 作用是啥? |
Beta Was this translation helpful? Give feedback.
-
“文档测试(Doc Test)”这部分必须是库项目才能直接cargo test运行,我本地是个二进制项目跑了半天也不好使😒 |
Beta Was this translation helpful? Give feedback.
-
给最后的混色函数完善了一下(也希望大家可以指出哪些地方可以优化): // src/lib.rs
//! # Art
//!
//! 未来的艺术建模库,现在的调色库
pub use self::kinds::PrimaryColor;
pub use self::kinds::SecondaryColor;
pub use self::utils::mix;
pub mod kinds {
//! 定义颜色的类型
/// 主色
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum PrimaryColor {
Red,
Yellow,
Blue,
}
/// 副色
#[derive(Debug,PartialEq)]
pub enum SecondaryColor {
Orange,
Green,
Purple,
}
}
pub mod utils {
//! 实用工具,目前只实现了调色板
use crate::kinds::*;
/// 将两种主色调成副色
/// ```rust
/// use art::utils::mix;
/// use art::kinds::{PrimaryColor,SecondaryColor};
/// assert!(matches!(mix(PrimaryColor::Yellow, PrimaryColor::Blue), SecondaryColor::Green));
/// ```
pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
match c1 {
PrimaryColor::Red => match c2 {
PrimaryColor::Red => panic!("Same primary color"),
PrimaryColor::Yellow => SecondaryColor::Orange,
PrimaryColor::Blue => SecondaryColor::Purple,
},
PrimaryColor::Yellow => match c2 {
PrimaryColor::Red => SecondaryColor::Orange,
PrimaryColor::Yellow => panic!("Same primary color"),
PrimaryColor::Blue => SecondaryColor::Green,
},
PrimaryColor::Blue => match c2 {
PrimaryColor::Red => SecondaryColor::Purple,
PrimaryColor::Yellow => SecondaryColor::Green,
PrimaryColor::Blue => panic!("Same primary color"),
}
}
}
} // src/main.rs
use art::PrimaryColor;
use art::mix;
fn main() {
let red = PrimaryColor::Red;
let blue = PrimaryColor::Blue;
let yellow = PrimaryColor::Yellow;
let primary_colors = [red, blue, yellow];
// println!("{:?}",mix(blue, yellow));
for i in 0..primary_colors.len() {
for j in (i+1)..primary_colors.len() {
let color1 = primary_colors[i];
let color2 = primary_colors[j];
println!("{:?} + {:?} = {:?}", color1, color2, mix(color1, color2))
}
}
} |
Beta Was this translation helpful? Give feedback.
-
basic/comment
https://course.rs/basic/comment.html
Beta Was this translation helpful? Give feedback.
All reactions