borrow-checker

    1熱度

    1回答

    我讀the builder pattern,然後試圖建立2個不同的製造商(Header和Request)如下: use std::ascii::AsciiExt; #[derive(PartialEq, Debug)] pub struct Headers<'a> (pub Vec<(&'a str, String)>); impl<'a> Headers<'a> { pub

    1熱度

    1回答

    結合我試圖生成Vec<(Point, f64)>: let grid_size = 5; let points_in_grid = (0..grid_size).flat_map(|x| { (0..grid_size) .map(|y| Point::new(f64::from(x), f64::from(y))) .collect::<Vec<Point>

    10熱度

    1回答

    我在VS2005的C#,.NET 3.0中編寫了一個應用程序,具有監視插入/彈出各種可移動驅動器(USB閃存盤,CD-ROM等)的功能。我不想使用WMI,因爲它可能有時是不明確的(例如,它可以爲單個USB驅動器產生多個插入事件),所以我簡單地覆蓋了我的mainform的WndProc以捕獲WM_DEVICECHANGE消息,如提議here。昨天我遇到了一個問題,事實證明,我將不得不使用WMI來檢索

    11熱度

    1回答

    我有this minimal example code: use std::borrow::BorrowMut; trait Foo {} struct Bar; impl Foo for Bar {} fn main() { let mut encryptor: Box<Foo> = Box::new(Bar); encrypt(encryptor.borrow

    0熱度

    1回答

    這是一個更高級別的問題,但我不確定哪些Rust功能應該用於改進問題。 採取的第一個步驟寫具有工具 API的圖形應用程序中,我們可能希望在context參數,它暴露了應用程序的各個部分通: // Where the data lives. struct Application { preferences: Preferences, windows: Vec<Windows>,

    1熱度

    1回答

    我可以使用像傳值類似的可變引用方法嗎?例如,我可以用 o.mth(&mut self, ...) 爲 o.mth(self, ...) 這將讓我無需擔心o壽命返回結果。它可能涉及一個move閉包,或某種包裝? 對於上下文,我試圖返回一個使用rust-csv包的CSV記錄盒裝迭代器,但迭代器不能超過讀者,Reader::records(&'t mut self)可變地借用。將其與BufRea

    12熱度

    1回答

    這裏發生了什麼(playground)? struct Number { num: i32 } impl Number { fn set(&mut self, new_num: i32) { self.num = new_num; } fn get(&self) -> i32 { self.num } } fn

    8熱度

    1回答

    此代碼失敗可怕借檢查(playground): struct Data { a: i32, b: i32, c: i32, } impl Data { fn reference_to_a(&mut self) -> &i32 { self.c = 1; &self.a } fn get_b(&self) ->

    0熱度

    3回答

    我似乎已經陷入了這個被稱爲「打擊借用檢查器」的洞中。我有以下功能: fn draw_pair(decks: &(&mut Deck, &mut Deck)) -> (Card, Card) { let (&mut p1, &mut p2) = decks; (p1.draw_card(), p2.draw_card()) } 我得到以下錯誤: expected type

    2熱度

    1回答

    我試圖在Rust中使用Snowball stemmer箱子來幹掉一個單詞向量。它應該是簡單的,但借檢查一直拒絕我的代碼: // Read user input let input = stdin(); let mut stemmer = Stemmer::new("english").unwrap(); for line in input.lock().lines() { let