我正在尝试通过cabal安装gtk,但是,在构建它时我遇到了以下类型错误
[ 22 of 209] Compiling Graphics.UI.Gtk.Embedding.Plug ( dist/build/Graphics/UI/Gtk/Embedding/Plug.hs, dist/build/Graphics/UI/Gtk/Embedding/Plug.o )
Graphics/UI/Gtk/Embedding/Plug.chs:120:6: error:
Couldn't match expected type ‘Ptr ()’
with actual type ‘Maybe DrawWindow’
In the first argument of ‘gtk_plug_new’, namely
‘(fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’
In the second argument of ‘($)’, namely
‘gtk_plug_new
(fromNativeWindowId (fromMaybe nativeWindowIdNone socketId))’
Graphics/UI/Gtk/Embedding/Plug.chs:137:6: error:
Couldn't match expected type ‘Ptr ()’
with actual type ‘Maybe DrawWindow’
In the second argument of ‘\ (Display arg1) arg2
-> withForeignPtr arg1
$ \ argPtr1 -> gtk_plug_new_for_display argPtr1 arg2’, namely …
Run Code Online (Sandbox Code Playgroud) 我正在panic::catch_unwind
惊慌失措:
use std::panic;
fn main() {
let result = panic::catch_unwind(|| {
panic!("test panic");
});
match result {
Ok(res) => res,
Err(_) => println!("caught panic!"),
}
}
Run Code Online (Sandbox Code Playgroud)
(游乐场)
这似乎工作得很好,但我仍然得到了恐慌的输出到stdout.我想这只打印出来:
caught panic!
Run Code Online (Sandbox Code Playgroud)
代替
thread '<main>' panicked at 'test panic', <anon>:6
note: Run with `RUST_BACKTRACE=1` for a backtrace.
caught panic!
Run Code Online (Sandbox Code Playgroud) 这段代码
use std::any::Any;
use std::collections::HashMap;
fn main() {
let x: HashMap<*const Any, i32> = HashMap::new();
}
Run Code Online (Sandbox Code Playgroud)
给我以下错误:
error: the trait `core::marker::Sized` is not implemented for the type `core::any::Any` [E0277]
let x: HashMap<*const Any, i32> = HashMap::new();
^~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
首先,我不明白为什么它是抱怨core::any::Any
,当键是类型*const core::any::Any
.*const _
无论它指向什么,都不应该是大小?为了测试这个,我试过:
use std::any::Any;
use std::mem::size_of;
fn main() {
println!("size_of(*const Any) = {}", size_of::<*const Any>());
}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,产生:
size_of(*const Any) = 16
Run Code Online (Sandbox Code Playgroud) 作为Coq中的练习,我试图证明以下函数返回一对长度相等的列表.
Require Import List.
Fixpoint split (A B:Set)(x:list (A*B)) : (list A)*(list B) :=
match x with
|nil => (nil, nil)
|cons (a,b) x1 => let (ta, tb) := split A B x1 in (a::ta, b::tb)
end.
Theorem split_eq_len : forall (A B:Set)(x:list (A*B))(y:list A)(z:list B),(split A B x)=(y,z) -> length y = length z.
Proof.
intros A B x.
elim x.
simpl.
intros y z.
intros H.
injection H.
intros H1 H2.
rewrite <- H1.
rewrite <- H2.
reflexivity. …
Run Code Online (Sandbox Code Playgroud) 我注意到,?Sized
是在类型参数绑定T
某些功能(borrow
,borrow_state
,和borrow_mut
),但是,它是不是一个界new
或into_inner
.如果我不能创建一个RefCell
包含动态大小(RefCell<T : ?Sized>
)的东西,那么它具有可以在这样的东西上运行的函数有什么用呢?
是否可以RefCell<Any>
在Rust中创建类型的东西?我尝试了以下方法:
fn test2<T : Any>(x : T) -> RefCell<Any>{
return RefCell::new(x) as RefCell<Any>
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
error: the trait `core::marker::Sized` is not implemented for the type `core::any::Any + 'static` [E0277]
<anon>:8 fn test2<T : Any>(x : T) -> RefCell<Any>{
Run Code Online (Sandbox Code Playgroud)
该文档RefCell
包括以下内容
pub struct RefCell<T> where T: ?Sized {
// some fields omitted
}
Run Code Online (Sandbox Code Playgroud)
这让我相信(连同这个问题的答案)这样的事情是可能的.我也尝试过:
fn test1<T : Any>(x : T) -> Box<Any>{
return Box::new(x) as Box<Any>
}
Run Code Online (Sandbox Code Playgroud)
哪个工作得很好.双方Box
并RefCell
似乎有类似的界限,所以我不太清楚,我在这里失踪.任何帮助将非常感激.我在Rust Playground有这个,如果有帮助的话.
我正在尝试在 LLDB 中调试并发程序,并且出现段错误,但不是在每次执行时。我想一遍又一遍地运行我的过程,直到它遇到段错误。到目前为止,我有以下几点:
b exit
breakpoint com add 1
Enter your debugger command(s). Type 'DONE' to end.
> run
> DONE
Run Code Online (Sandbox Code Playgroud)
我觉得烦人的部分是,当我到达退出函数并命中我的断点时,当run
命令被执行时,我从 LLDB 收到以下提示:
There is a running process, kill it and restart?: [Y/n]
Run Code Online (Sandbox Code Playgroud)
我想自动重启进程,不用Y
每次都手动输入。有人知道怎么做吗?
我通过FFI在Haskell中导入一些东西,并希望能够用lldb调试它们.例如,我可能有以下Haskell文件(test.hs):
main = do
foo
return()
foreign import ccall "foo" foo :: IO ()
Run Code Online (Sandbox Code Playgroud)
以下C文件(ctest.c):
#include <stdio.h>
void foo(){
printf("test\n");
}
Run Code Online (Sandbox Code Playgroud)
然后我可以编译它ghc test.hs ctest.c
.如果我通过LLDB运行可执行文件,我可以设置一个断点foo
,但是,它只给我汇编代码,例如:
test`foo: ->
0x1000019e0 <+0>: pushq %rbp
0x1000019e1 <+1>: movq %rsp, %rbp
0x1000019e4 <+4>: subq $0x10, %rsp
0x1000019e8 <+8>: leaq 0x33eb31(%rip), %rdi ; "test\n"
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉GHC编译我通过FFI导入的C文件,-g
以便我可以获得调试符号?
我一直无法使用 Cabal 安装任何软件包,收到一条错误消息,指出 tar 存档不在预期目录中。例如,如果我尝试这样做cabal install mtl
,我会收到以下错误:
正在解决依赖项...无法安装 text-1.2.1.1 cabal:错误:某些软件包无法安装:text-1.2.1.1 在解压缩软件包时失败。例外是:用户错误(tar 存档中的文件不在预期目录中。预期:“.”但得到以下层次结构:[“text-1.2.1.1”])
我已经运行cabal update
,并cabal --version
给出以下内容:
$ cabal --version
cabal-install version 1.22.5.0
using version 1.22.4.0 of the Cabal library
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么会发生这种情况?如果您需要任何其他信息,请告诉我。