Types 如何表示这些数据?

Types 如何表示这些数据?,types,architecture,rust,Types,Architecture,Rust,我对该主题的研究已被正确地确定为 我正试图创建一个资源管理板条箱来决定谁可以租用地板。公共界面(当前)看起来有点像: pub struct Bid<T> { max_bid: TokenPerNanoSecond, budget: Token, data: T } /// Returns a vector of tuples of (T, time of rent end, tokens spent) pub fn who_rents_the_flooble

我对该主题的研究已被正确地确定为

我正试图创建一个资源管理板条箱来决定谁可以租用地板。公共界面(当前)看起来有点像:

pub struct Bid<T> {
    max_bid: TokenPerNanoSecond,
    budget: Token,
    data: T
}

/// Returns a vector of tuples of (T, time of rent end, tokens spent)
pub fn who_rents_the_flooble<'a, T>(
    mut bids: Vec<&'a mut Bid<T>>
) -> Vec<(T, NanoSecond, Token)> {
    let mut output = vec![];
    let mut now = NanoSecond::from(0);
    // while bids.len() > 0 {
        // run a mini auction to work out who wins
        // increment now by the duration
        // append winner's data, now and amount spent to output
        // subtract amount spent from winner's budget
        // remove bids with no budget left
    // }
    output
}
pub fn who_rents_the_flooble<T>(
    mut bids: Vec<Bid<T>>
) -> Vec<(T, NanoSecond, Token)>
pub-struct-Bid{
最高出价:每纳秒,
预算:代币,
数据:T
}
///返回一个元组向量(T,租用结束时间,所用令牌)
谁租地板的酒吧
)->Vec{
让mut output=vec![];
让mut now=纳秒::from(0);
//而bids.len()>0{
//进行一次小型拍卖,确定谁获胜
//现在按持续时间递增
//将获胜者的数据、现在和花费的金额追加到输出中
//从获胜者的预算中减去花费的金额
//删除没有剩余预算的投标
// }
输出
}
Token
NanoSecond
TokenPerNanoSecond
u64
的新类型,它们的算术关系已完全定义;它们的出现主要是因为我不擅长代数,不希望因为我的基本代数错误和语义不同数据的混淆而出现细微的错误

T
是一个完全不透明的东西。这是C回调的
void*
,作为调用者识别输入和输出之间关系的一种方式


然而,
Vec所有这些问题都可以通过简单地获得向量的所有权来解决;您的原型应如下所示:

pub struct Bid<T> {
    max_bid: TokenPerNanoSecond,
    budget: Token,
    data: T
}

/// Returns a vector of tuples of (T, time of rent end, tokens spent)
pub fn who_rents_the_flooble<'a, T>(
    mut bids: Vec<&'a mut Bid<T>>
) -> Vec<(T, NanoSecond, Token)> {
    let mut output = vec![];
    let mut now = NanoSecond::from(0);
    // while bids.len() > 0 {
        // run a mini auction to work out who wins
        // increment now by the duration
        // append winner's data, now and amount spent to output
        // subtract amount spent from winner's budget
        // remove bids with no budget left
    // }
    output
}
pub fn who_rents_the_flooble<T>(
    mut bids: Vec<Bid<T>>
) -> Vec<(T, NanoSecond, Token)>
pub fn谁出租地板(
mut出价:Vec
)->Vec

通过值传递,而不是通过引用,解决了问题。

为什么不直接接受
Vec
?@Shepmaster我大约2小时前就想到了这一点,它似乎解决了大部分问题。我本打算在写答案之前完成程序的编写,只是为了确定。