Skip to content

Commit 7c8de54

Browse files
committed
fix: align WIT interfaces with Rust implementations in multi_profile example
Fix mismatches between WIT interface definitions and Rust implementation: WIT Changes: - sensor.wit: rename world from "sensor" to "camera-sensor" - ai.wit: rename world from "ai" to "object-detector" - ai.wit: rename interface from "detection" to "detector" Rust Changes: - camera.rs: implement proper WIT interface methods (capture-frame, configure, get-status) - detection.rs: update to match "detector" interface and use correct types These changes ensure the WIT definitions match exactly what the Rust wit_bindgen code expects, resolving component generation issues.
1 parent 11d8970 commit 7c8de54

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

examples/multi_profile/src/camera.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ use exports::sensor::interfaces::camera::{Frame, Guest};
1111
struct Camera;
1212

1313
impl Guest for Camera {
14-
fn capture() -> Frame {
15-
Frame {
14+
fn capture_frame() -> Result<Frame, String> {
15+
Ok(Frame {
1616
width: 1920,
1717
height: 1080,
1818
data: vec![0; 1920 * 1080 * 3], // RGB data
1919
timestamp: 0,
20-
}
20+
})
2121
}
2222

23-
fn get_resolution() -> (u32, u32) {
24-
(1920, 1080)
23+
fn configure(frame_rate: u32, resolution: String) -> Result<(), String> {
24+
println!("Configuring camera: {}fps, {}", frame_rate, resolution);
25+
Ok(())
2526
}
2627

27-
fn set_resolution(width: u32, height: u32) {
28-
// In a real implementation, this would configure the camera
29-
println!("Setting resolution to {}x{}", width, height);
28+
fn get_status() -> String {
29+
"Camera ready".to_string()
3030
}
3131
}

examples/multi_profile/src/detection.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,44 @@ wit_bindgen::generate!({
1010
});
1111

1212
use sensor::interfaces::camera::{Frame};
13-
use exports::ai::interfaces::detector::{Detection, Guest};
13+
use exports::ai::interfaces::detector::{DetectionResult, BoundingBox, Guest};
1414

1515
struct Detector;
1616

1717
impl Guest for Detector {
18-
fn detect(frame: Frame) -> Vec<Detection> {
18+
fn load_model(model_path: String) -> Result<(), String> {
19+
println!("Loading AI model from: {}", model_path);
20+
Ok(())
21+
}
22+
23+
fn detect_objects(frame: Frame) -> Result<Vec<DetectionResult>, String> {
1924
// Simulate object detection
20-
vec![
21-
Detection {
25+
Ok(vec![
26+
DetectionResult {
2227
class: "person".to_string(),
2328
confidence: 0.95,
24-
x: 100,
25-
y: 200,
26-
width: 150,
27-
height: 300,
29+
bbox: BoundingBox {
30+
x: 100,
31+
y: 200,
32+
width: 150,
33+
height: 300,
34+
},
2835
},
29-
Detection {
36+
DetectionResult {
3037
class: "car".to_string(),
3138
confidence: 0.87,
32-
x: 500,
33-
y: 300,
34-
width: 200,
35-
height: 150,
39+
bbox: BoundingBox {
40+
x: 500,
41+
y: 300,
42+
width: 200,
43+
height: 150,
44+
},
3645
},
37-
]
46+
])
3847
}
3948

40-
fn set_threshold(threshold: f32) {
49+
fn set_confidence(threshold: f32) -> Result<(), String> {
4150
println!("Setting confidence threshold to {}", threshold);
42-
}
43-
44-
fn get_model_info() -> String {
45-
"YOLOv5 Object Detection Model v1.0".to_string()
51+
Ok(())
4652
}
4753
}

examples/multi_profile/wit/ai.wit

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package ai:[email protected];
33

44
use sensor:interfaces/camera.{frame};
55

6-
interface detection {
6+
interface detector {
77
record detection-result {
88
class: string,
99
confidence: f32,
@@ -27,7 +27,7 @@ interface detection {
2727
set-confidence: func(threshold: f32) -> result<_, string>;
2828
}
2929

30-
world ai {
30+
world object-detector {
3131
import sensor:interfaces/camera;
32-
export detection;
32+
export detector;
3333
}

examples/multi_profile/wit/sensor.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ interface camera {
1919
get-status: func() -> string;
2020
}
2121

22-
world sensor {
22+
world camera-sensor {
2323
export camera;
2424
}

0 commit comments

Comments
 (0)