warning: fields buffer and indices are never read
--> src\graphics\internal_canvas.rs:689:9
|
688 | pub struct InstanceArrayView {
| ----------------- fields in this struct
689 | pub buffer: ArcBuffer,
| ^^^^^^
690 | pub indices: ArcBuffer,
| ^^^^^^^
|
= note: has a derived impl for the trait , but this is intentionally ignored during dead code analysis
= note: on by default
Assistant
User
warning: fields buffer and indices are never read
--> src\graphics\internal_canvas.rs:689:9
|
688 | pub struct InstanceArrayView {
| ----------------- fields in this struct
689 | pub buffer: ArcBuffer,
| ^^^^^^
690 | pub indices: ArcBuffer,
| ^^^^^^^
|
= note: InstanceArrayView has a derived impl for the trait Debug, but this is intentionally ignored during dead code analysis
= note: #[warn(dead_code)] on by default
warning: method append is never used
--> src\vfs.rs:112:8
|
97 | pub trait VFS: Debug {
| --- method in this trait
...
112 | fn append(&self, path: &Path) -> GameResult<Box> {
| ^^^^^^
warning: method len is never used
--> src\vfs.rs:149:8
|
140 | pub trait VMetadata {
| --------- method in this trait
...
149 | fn len(&self) -> u64;
| ^^^
Assistant
User
warning: fields buffer and indices are never read
--> src\graphics\internal_canvas.rs:689:9
|
688 | pub struct InstanceArrayView {
| ----------------- fields in this struct
689 | pub buffer: ArcBuffer,
| ^^^^^^
690 | pub indices: ArcBuffer,
| ^^^^^^^
|
= note: has a derived impl for the trait , but this is intentionally ignored during dead code analysis
= note: on by default
Assistant
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
use std::time::Duration;
const BUFFER_SIZE: usize = 5;
struct SharedBuffer {
buffer: Vec<i32>,
condvar: Condvar,
}
impl SharedBuffer {
fn new() -> Self {
SharedBuffer {
buffer: Vec::with_capacity(BUFFER_SIZE),
condvar: Condvar::new(),
}
}
fn produce(&mut self, item: i32) {
while self.buffer.len() == BUFFER_SIZE {
// 緩衝區已滿,等待消費者消耗資料
self.condvar.wait().unwrap();
}
self.buffer.push(item);
println!("Produced: {}", item);
// 通知消費者
self.condvar.notify_one();
}
fn consume(&mut self) -> i32 {
while self.buffer.is_empty() {
// 緩衝區為空,等待生產者生產資料
self.condvar.wait().unwrap();
}
let item = self.buffer.remove(0);
println!("Consumed: {}", item);
// 通知生產者
self.condvar.notify_one();
item
}
}
fn main() {
let shared_buffer = Arc::new(Mutex::new(SharedBuffer::new()));
let buffer_clone = Arc::clone(&shared_buffer);
// 生產者線程
let producer = thread::spawn(move || {
for i in 0..10 {
let mut buffer = buffer_clone.lock().unwrap();
buffer.produce(i);
thread::sleep(Duration::from_millis(500)); // 模擬生產所需的時間
}
});
// 消費者線程
let consumer = thread::spawn(move || {
for _ in 0..10 {
let mut buffer = shared_buffer.lock().unwrap();
buffer.consume();
thread::sleep(Duration::from_millis(700)); // 模擬消費所需的時間
}
});
// 等待線程完成
producer.join().unwrap();
consumer.join().unwrap();
}
warning: method append is never used
--> src\vfs.rs:112:8
|
97 | pub trait VFS: Debug {
| --- method in this trait
...
112 | fn append(&self, path: &Path) -> GameResult<Box> {
| ^^^^^^
warning: method len is never used
--> src\vfs.rs:149:8
|
140 | pub trait VMetadata {
| --------- method in this trait
...
149 | fn len(&self) -> u64;
| ^^^
warning: ggez (lib) generated 3 warnings
Compiling ggez v0.9.3 (C:\Users\fer52\ggez-master)
error[E0061]: this method takes 1 argument but 0 arguments were supplied
--> examples\01_super_simple_1.rs:23:26
|
23 | self.condvar.wait().unwrap();
| ^^^^-- argument #1 of type MutexGuard<'_, _> is missing
|
note: method defined here
--> C:\Users\fer52.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\sync\condvar.rs:189:12
|
189 | pub fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> LockResult<MutexGu...
| ^^^^
help: provide the argument
|
23 | self.condvar.wait(/* guard */).unwrap();
| ~~~~~~~~~~~~~
error[E0061]: this method takes 1 argument but 0 arguments were supplied
--> examples\01_super_simple_1.rs:34:26
|
34 | self.condvar.wait().unwrap();
| ^^^^-- argument #1 of type MutexGuard<'_, _> is missing
|
note: method defined here
--> C:\Users\fer52.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\sync\condvar.rs:189:12
|
189 | pub fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> LockResult<MutexGu...
| ^^^^
help: provide the argument
|
34 | self.condvar.wait(/* guard */).unwrap();
| ~~~~~~~~~~~~~
For more information about this error, try rustc --explain E0061.
你的程式碼中有幾個問題導致了上述警告和錯誤。我會為你逐個分析和修正。
錯誤:this method takes 1 argument but 0 arguments were supplied
warning: ggez (lib) generated 3 warnings
Compiling ggez v0.9.3 (C:\Users\fer52\ggez-master)
error[E0599]: no method named lock found for mutable reference &mut SharedBuffer in the current scope
--> examples\01_super_simple_1.rs:24:49
|
24 | let _guard = self.condvar.wait(self.lock().unwrap()).unwrap();
| ^^^^ method not found in &mut SharedBuffer
error[E0599]: no method named lock found for mutable reference &mut SharedBuffer in the current scope
--> examples\01_super_simple_1.rs:36:49
|
36 | let _guard = self.condvar.wait(self.lock().unwrap()).unwrap();
| ^^^^ method not found in &mut SharedBuffer
For more information about this error, try rustc --explain E0599.
warning: method append is never used
--> src\vfs.rs:112:8
|
97 | pub trait VFS: Debug {
| --- method in this trait
...
112 | fn append(&self, path: &Path) -> GameResult<Box> {
| ^^^^^^
warning: method len is never used
--> src\vfs.rs:149:8
|
140 | pub trait VMetadata {
| --------- method in this trait
...
149 | fn len(&self) -> u64;
| ^^^
warning: ggez (lib) generated 3 warnings
Compiling ggez v0.9.3 (C:\Users\fer52\ggez-master)
error[E0308]: mismatched types
--> examples\01_super_simple_1.rs:23:31
|
23 | self.condvar.wait(self).unwrap();
| ---- ^^^^ expected MutexGuard<'_, _>, found &mut SharedBuffer
| |
| arguments to this method are incorrect
|
= note: expected struct MutexGuard<'_, _>
found mutable reference &mut SharedBuffer
note: method defined here
--> C:\Users\fer52.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\sync\condvar.rs:189:12
|
189 | pub fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> LockResult<MutexGu...
| ^^^^
error[E0308]: mismatched types
--> examples\01_super_simple_1.rs:34:31
|
34 | self.condvar.wait(self).unwrap();
| ---- ^^^^ expected MutexGuard<'_, _>, found &mut SharedBuffer
| |
| arguments to this method are incorrect
|
= note: expected struct MutexGuard<'_, _>
found mutable reference &mut SharedBuffer
note: method defined here
--> C:\Users\fer52.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\sync\condvar.rs:189:12
|
189 | pub fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> LockResult<MutexGu...
| ^^^^
For more information about this error, try rustc --explain E0308.