Unwrap()是一个函数,它提取一个Option或Result中的值,如果值不存在,则引发panic 。 Unwrap() is a function that extracts the value inside an Option or Result and panics if no value is present. 如果索引超出了数组长度,Rust会panic ,这是Rust术语,它用于程序因为错误而退出的情况。 If the index is greater than the length, Rust will panic , which is the term Rust uses when a program exits with an error. Panic 出现在了多种精选集里,并且在"VG-lista"获得了nr.10的佳绩。Panic was on several collection albums, and made it's best place on the“VG-lista” with place nr.10.函数的契约,尤其是当违反它会造成panic 的契约,应该在函数的API文档中得到解释。 Contracts for a function, especially when a violation will cause a panic , should be explained in the API documentation for the function. 它还检查调用深度(当前最大值为1000),以避免无限递归的panic 。 It also checks the call depth(currently maximum 1000), to avoid a panic in case of unbounded recursion.
第九章讲到了最简单的造成panic 的方法:调用panic ! We talked about the simplest way to cause a panic in Chapter 9, which is to call the panic ! macro! 试图将切片超越其容量,将超出数组的极限,并将触发panic 。 Trying to grow the slice beyond its capacity will step beyond the limits of the array and will trigger a panic . 因为截止日期的存在,使拖延的影响被限制在一个较短的期限内,最终会因为ThePanic Monster的介入而消除。 And when there's deadlines, the effects of procrastination are contained to the short term because the Panic Monster gets involved. 第一行显示了panic 提供的信息并指明了源码中panic 出现的位置:src/main. The first line shows our panic message and the place in our source code where the panic occurred: src/main. Warning用mount(8)命令去装载CD光盘,至少会产生一个错误,更糟的情况下会产生kernelpanic 。 Warning: Trying to mount audio CDs with the mount(8) command will result in an error, at least, and a kernel panic , at worst. 这样的一个应急(panic !)会导致我们的程序崩溃,并且会显示你传递的信息。 A panic ! like this will cause our program to crash, displaying the message.列表3的第一行显示panic 发生前运行的goroutine是id为1的goroutine。 The stack trace on line 01 in listing 3 is showing that goroutine 1 was running prior to the panic .不再通过expect允许程序panic ,run函数将会在出错时返回一个Result<T,E>。 Instead of allowing the program to panic by calling expect, the run function will return a Result<T, E> when something goes wrong. 示例9-1:尝试访问超越vector结尾的元素,这会造成panic ! Listing 9-1: Attempting to access an element beyond the end of a vector, which will cause a call to panic ! 当运行这段代码,你会发现对于第一个[]方法,当引用一个不存在的元素时Rust会造成panic 。 When we run this code, the first[] method will cause the program to panic because it references a nonexistent element. 示例9-4中的代码不管File::open是因为什么原因失败都会panic ! The code in Listing 9-4 will panic ! no matter why File::open failed! 使用expect而不是unwrap并提供一个好的错误信息可以表明你的意图并更易于追踪panic 的根源。 Using expect instead of unwrap and providing good error messages can convey your intent and make tracking down the source of a panic easier. 看起来不错!现在在代码中引入bug,移除new函数在值大于100时会panic 的条件:. Now let's introduce a bug in our code by removing the condition that the new function will panic if the value is greater than 100. 还有另一个类似于unwrap的方法它还允许我们选择panic ! Another method, expect, which is similar to unwrap, lets us also choose the panic ! 月1日,任天堂修改了《DokiDokiPanic 》,并且以《超级马里奥兄弟2》在北美和欧洲地区NintendoEntertainmentSystem发行。 September 1, Nintendo revamps Doki Doki Panic and releases it as Super Mario Bros. 2, for the Nintendo Entertainment System in America and the PAL region.
Display more examples
Results: 135 ,
Time: 0.0242