小编Maa*_*ten的帖子

Rust 通用值内存存储实现

我正在为对象存储开发一个 API,并且正在努力寻找一种在 Rust 中实现它的方法。这有点令人沮丧,因为我很清楚如何在 C++ 中做到这一点,所以也许这个设计从根本上不适合 Rust,但我希望这里的人们能够提供一些有用的见解。

我希望能够执行以下操作:

// This is clone & copy
struct Id<Identifiable> {
  // What I think would be needed to get this entire system 
  // to work, but it is not fixed like this so alternate 
  // ideas are welcome.
  raw_id: usize,
  _marker: PhantomData<Identifiable>,
}

struct Store {
  // ... don't know how to implement this
}

trait Object {
  // ... some behavior
}

struct ObjectA {}
impl Object for ObjectA {}

struct ObjectB …
Run Code Online (Sandbox Code Playgroud)

software-design rust

3
推荐指数
1
解决办法
307
查看次数

标签 统计

rust ×1

software-design ×1