小编RKS*_*RKS的帖子

从Option <T>中提取类型T.

我有一些由bindgen生成的代码,其中包含由函数指针表示的函数Option<T>.

pub type SomeFnPointerType = ::std::option::Option<
  unsafe extern "C" fn ( /* .. large number of argument types .. */) 
    -> /* return type */
> ;
Run Code Online (Sandbox Code Playgroud)

我想将未包装的值存储在结构中.但是,内部函数指针类型没有类型别名,那么如何定义该结构呢?我无法重构代码,因为它是自动生成的.

我想做这样的事情(用C++'ish伪代码):

struct FunctionTable {
  decltype((None as SomeFnPointerType).unwrap()) unwrappedFn;
  /* ... */
};
Run Code Online (Sandbox Code Playgroud)

或者也许只是SomeFnPointerType::T在允许的情况下.

在Rust中可以实现吗?如果没有,我看到的唯一方法是通过将生成的文件中的代码复制粘贴到单独的手写文件中手动定义这些类型,并手动保持类型同步.

rust

7
推荐指数
1
解决办法
65
查看次数

Diamond继承和Common Lisp对象系统

我试图找到Common Lisp CLOS中典型钻石继承问题的解决方案.代码 :

(defclass C1.0 () ... )
(defclass C2.1 (C1.0) ...)
(defclass C2.2 (C1.0) ...)
(defclass C3.0 (C2.1 C2.2) ...)

(defmethod m1 ((obj C1.0)) ...)
(defmethod m1 ((obj C2.1)) ...)
(defmethod m1 ((obj C2.2)) ...)
(defmethod m1 ((obj C3.0))
  ; Here I want to call the C2.2 version of
  ; m1
  ...)
Run Code Online (Sandbox Code Playgroud)

还假设C1.0,C2.1和C2.2的代码在我无法访问的库中,所以我无法修改那里的任何内容.Furthur,假设其他一些类也将派生自C2.2并且可能不想调用m2的C2.2版本,所以我无法在C2.2中添加任何东西:before.使用call-next-method将调用C2.1版本.

只是为了澄清,这是如何在Python中解决它:

class C1_0 :
  def m1 (self) : ...

class C2_1 (C1_0) :
  def m1 (self) : ...

class …
Run Code Online (Sandbox Code Playgroud)

lisp inheritance common-lisp clos diamond-problem

4
推荐指数
1
解决办法
487
查看次数

标签 统计

clos ×1

common-lisp ×1

diamond-problem ×1

inheritance ×1

lisp ×1

rust ×1