因此在Windows中,您可以使用该PlaySound功能在C++应用程序中播放MP3文件.在Mac OS X/Linux中可以使用哪些类似的功能?如果你能链接到一些示例的Hello-World类型程序,我也将不胜感激.
mod simulation;
use simulation::factory::FactoryType;
Run Code Online (Sandbox Code Playgroud)
工作得很好main.rs,但不在doctest里面simulation/factory.rs:
impl product_type::ProductType for FactoryType {
/// Lorem Ipsum
///
/// # Examples
///
/// ```
/// use simulation::factory::FactoryType;
///
/// ...
/// ```
fn human_id(&self) -> &String {
...
}
}
Run Code Online (Sandbox Code Playgroud)
cargo test 给了我错误
---- simulation::factory::human_id_0 stdout ----
<anon>:2:9: 2:19 error: unresolved import `simulation::factory::FactoryType`. Maybe a missing `extern crate simulation`?
<anon>:2 use simulation::factory::FactoryType;
^~~~~~~~~~
error: aborting due to previous error
thread 'simulation::factory::human_id_0' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:192
Run Code Online (Sandbox Code Playgroud)
我怎样才能让doctests工作?
我有以下简化代码,其中struct A包含某个属性.我想A从该属性的现有版本创建新实例,但是如何使该属性的新值的生命周期超过函数调用?
pub struct A<'a> {
some_attr: &'a str,
}
impl<'a> A<'a> {
fn combine(orig: &'a str) -> A<'a> {
let attr = &*(orig.to_string() + "suffix");
A { some_attr: attr }
}
}
fn main() {
println!("{}", A::combine("blah").some_attr);
}
Run Code Online (Sandbox Code Playgroud)
上面的代码产生
error[E0597]: borrowed value does not live long enough
--> src/main.rs:7:22
|
7 | let attr = &*(orig.to_string() + "suffix");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not live long enough
8 | A { some_attr: attr }
9 | }
| …Run Code Online (Sandbox Code Playgroud) 所以我正在制作一个带有传送和常用老鼠的蛇游戏.我有一个像这样运行的循环:
while(snake.alive() && miceEaten < micePerLevel)
{
displayInfo(lives, score, level, micePerLevel - miceEaten);
//some code
if(miceEaten())
{
//update score...
}
//more stuff...
}
Run Code Online (Sandbox Code Playgroud)
上述代码的问题是displayInfo在得分更新之前调用,因此在吃完鼠标之后,用户必须等到循环再次运行才能看到他的分数更新.所以我将这一行代码移到了函数的底部:
while(snake.alive() && miceEaten < micePerLevel)
{
//some code
if(miceEaten())
{
//update score...
}
//more stuff...
displayInfo(lives, score, level, micePerLevel - miceEaten);
}
Run Code Online (Sandbox Code Playgroud)
和传送停止工作!只要蛇到达传送,程序就会崩溃.并displayInfo使用以下代码:
stringstream s;
s << "LEVEL " << left << setw(12) << level << "LIVES: " << setw(12) << lives << "MICE LEFT: " << setw(12) << miceLeft
<< "SCORE: …Run Code Online (Sandbox Code Playgroud) 如果我有一个指向从抽象基类派生的对象的指针(因此我无法创建该类的新对象),并且我希望对所述对象进行深层复制,那么是否有更简洁的方法来实现让抽象基类创建一个新的纯虚copy函数,每个继承类必须实现?
由于Safari和Chrome都使用Webkit,如果网页看起来很好,那么测试两种浏览器的兼容性是多余的吗?
我想将值设置为变量列表,如下所示:
list[[1]] = 2
Run Code Online (Sandbox Code Playgroud)
如果list[[1]]是a,那么a现在将等于两个.我怎样才能做到这一点?
我想做一些类似于此的事情:
(defstruct person
real-name
(fake-name real-name)) ;if fake-name not supplied, default to real-name
Run Code Online (Sandbox Code Playgroud)
但是,Common Lisp说The variable REAL-NAME is unbound.如何让构造函数按顺序评估它的参数(就像我可以使用函数关键字参数),或者我应该如何做得更好呢?
假设我有两个div和A,它们目前并排排列.如何让A与B分开50px,同时仍然让A占据剩余空间的70%而B剩下的30%?
编辑:在我实际尝试之前一点接受答案.哎呦.
JSFiddles:
现在分开了,但是现在第二个就在第二行?
所以我目前有这个代码:
(ns contact-form.core
(:gen-class))
(def foo "Hello World!")
(defn some-func [a-symbol]
(println (str a-symbol "'s value is: " (eval a-symbol))))
(defn -main [& args]
(some-func 'foo))
Run Code Online (Sandbox Code Playgroud)
我这样做之后C-c C-k在Emacs,我得到以下的输出:
contact-form.core> (-main)
foo's value is: Hello World!
nil
Run Code Online (Sandbox Code Playgroud)
但是当我执行lein uberjar并运行生成的jar文件时,我收到一个错误:
Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: foo in this context, compiling:(NO_SOURCE_PATH:0)
at clojure.lang.Compiler.analyze(Compiler.java:6235)
at clojure.lang.Compiler.analyze(Compiler.java:6177)
at clojure.lang.Compiler.eval(Compiler.java:6469)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at contact_form.core$some_func.invoke(core.clj:7)
at contact_form.core$_main.doInvoke(core.clj:10)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:159)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at contact_form.core.main(Unknown Source)
Caused …Run Code Online (Sandbox Code Playgroud)