在Rust中使用“match”和嵌套的“enum”有很多方法可以解决这个问题;你选择哪一个当然部分是你的设计决定,部分取决于使用情况。我想到了几个选择:
fnignore_values(value:(i32,i32)){match value{(_,0)=>println!("Ignore the second value"),(x,_)=>println!("x: {}",x),}}fnmain(){ignore_values((10,0));// Output: Ignore the second valueignore_values((20,30));// Output: x: 20} 在上述代码中,ignore_values函数接收一个元组作...
The function returns the enum with doubled values. The function also copies the discriminant field to the enum being returned.; The caller passes the following parameters: ; 🔡 rsi: Address of the enum ; 🔡 rdi: Address of the enum to be returned. example::double: mov rax, rdi ; ...
总结起来,rust/compiler/rustc_mir_dataflow/src/rustc_peek.rs文件的作用是实现用于检查MIR流程的peek功能,通过SanityCheck结构体进行MIR数据流分析的断言验证,通过PeekCall结构体跟踪函数调用并记录相关信息,通过RustcPeekAt<'tcx> trait定义MIR的peek功能,以及通过PeekCallKind enum定义peek检查的类型。 File: rust/...
match m {} 模式匹配BK EX REF, 下面跟匹配分支. 参见下表. let S(x) = get(); 显然, let 也和下表的模式匹配类似. let S { x } = s; 仅将x 绑定到值 s.x. let (_, b, _) = abc; 仅将b 绑定到值 abc.1. let (a, ..) = abc; 也可以将「剩余的」都忽略掉. let (.., a...
{ id: i32, name: String, description: Option<String>, owner: GithubUser, stargazers_url: String, commits_url: String, contributors_url: String, } pub enum URL { WithBaseUrl(&'static str), WithoutBaseUrl(String), } impl URL { pub fn value(self) -> String { match self { URL::...
#![feature(const_fn)] pub enum A { B, C, } const fn foo(a: A) { match a { A::B => (), A::C => (), } } fn main() {} playpen: https://is.gd/n7pDFb rustc 1.17.0-nightly (e703b33e3 2017-03-23) error: internal compiler error: /checkout/src/li...
Struct or enum constants that don't derive PartialEq & Eq used match patterns is now a hard error This was previously a warning. Lifetimes named '_ are no longer allowed. This was previously a warning. From the pound escape, lines consisting of multiple #s are now visible It is an error...
14 candidates.insert(leaf_values[i]); 15 } 16 return num_candidates_found as i32; 17 } 18 Node::Inner(inner) => { 19 let above = (*inner).hyperplane.point_is_above(&query); 20 let (main, backup) = match above { 21 true => (&(inner.right_node), &(inner.left_node)), ...
Although Rust is a relatively low-level language, Rust has some functional concepts that are generally found in higher-level languages. This makes Rust not only fast, but also easy and efficient to code in. // This is a comment. Line comments look like this...// and extend multiple lines...