1 个不稳定版本

使用旧的 Rust 2015

0.0.1 2016年4月29日

#4#tmp

CC0 许可证

4KB

问题

pub struct Foo {
    ...
}

impl Foo {
    fn do_something(&mut self, ...){
        //FIXME: avoid allocation. can't fix this because T is lifetime-bound.
        let mut guards: Vec<Guard<'x>> = Vec::with_capacity(xxx.len());
        ...
    }
}

解决方案

use tmp_vec::TmpVec;

pub struct Foo {
    tmp_guards: TmpVec<Guard<'static>>,
    ...
}

impl Foo {
    fn do_something(&mut self, ...){
         let mut guards = self.tmp_guards.borrow_mut();
         ...
    }
}
        

lib.rs:

问题

pub struct Foo {
    ...
}

impl Foo {
    fn do_something(&mut self, ...){
        //FIXME: avoid allocation. can't fix this because T is lifetime-bound.
        let mut guards: Vec<Guard<'x>> = Vec::with_capacity(xxx.len());
        ...
    }
}

解决方案

use tmp_vec::TmpVec;

pub struct Foo {
    tmp_guards: TmpVec<Guard<'static>>,
    ...
}

impl Foo {
    fn do_something(&mut self, ...){
         let mut guards = self.tmp_guards.borrow_mut();
         ...
    }
}
        

无运行时依赖