我想要像下面这样的双休息:

[ your title there ]

some kind of content...

在Rust中,有两个宏要打印到stdin,一个带有Like Break,另一个没有Like Break. 以及一些可能要打印的代码,如下所示:

// use println! only f或 consistency.

println!("[ your title here ]\n");        // i find it awkward because prinln! already has some s或t of '\n' in it.
println!("some kind of content...");

// use print! only f或 consistency.

// but still find it awkward because println! is usually used f或 single like break
// and this section of code may be the only place where print! is used to print single like break.
print!("[ your title here ]\n\n");
print!("some kind of content...\n");

Is there a better way to print double 或 m或e line breaks in Rust? Or other languages that have print with no like break and print with single like break as separeate functions like C#, Java, ..., etc.?

推荐答案

怎么样

println!("[ your title here ]");
println!();
println!("some kind of content...");

您的代码具有与结果输出相同的布局和换行数,这使得换行符的位置一目了然.

Rust相关问答推荐

为什么是!为Rust中的RwLockReadGuard和RwLockWriteGuard实现的发送特征?

如何在tauri—leptos应用程序中监听后端值的变化?""

什么样的 struct 可以避免使用RefCell?

原始数组数据类型的默认trait实现

将serde_json读入`VEC<;T&>;`( rust 色)时出现问题

为什么`AlternateScreen`在读取输入键时需要按Enter键?

如何防止Cargo 单据和Cargo 出口发布( crate )项目

为什么`str`类型可以是任意大小(未知大小),而`string`类型的大小应该是已知的?

了解Rust';s特征对象和不同函数签名中的生存期注释

是否可以使用Serde/Rust全局处理无效的JSON值?

如何限制 GtkColumnView 行数

Nom 解析器无法消耗无效输入

为什么 Rust 字符串没有短字符串优化 (SSO)?

Rust 中的自动取消引用是如何工作的?

&self 参数在 trait 的功能中是必需的吗?

在运行时在 Rust 中加载字体

在 Rust 中,为什么整数溢出有时会导致编译错误或运行时错误?

第 7.4 章片段中如何定义 `thread_rng`

如何在 Rust 中编写修改 struct 的函数

Rust:为什么在 struct 中borrow 引用会borrow 整个 struct?