在 Rust 的一行中为多个变量分配一个值? [英] Assign a single value to multiple variables in one line in Rust?

查看:54
本文介绍了在 Rust 的一行中为多个变量分配一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分配多个变量的常用方法通常在 C 或 Python 等编程语言中表示为:

A common way to assign multiple variables is often expressed in programming languages such as C or Python as:

a = b = c = value;

在 Rust 中是否有与此等效的,或者您需要将其写出来?

Is there an equivalent to this in Rust, or do you need to write it out?

a = value;
b = value;
c = value;

<小时>

抱歉,如果这很明显,但我所有的搜索都导致了有关元组分配的问答.


Apologies if this is obvious, but all my searches lead to Q&A regarding tuple assignment.

推荐答案

不,没有等价物.是的,您必须编写多项作业,或者编写一个本身进行多项作业的宏.

No, there is no equivalent. Yes, you have to write multiple assignments, or write a macro which itself does multiple assignments.

这篇关于在 Rust 的一行中为多个变量分配一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆