1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crateTransform;
use FfiSensorData;
use SharedPtr;
use Derivative;
use assert_impl_all;
/// Base trait for all sensor data types.
///
/// Provides common methods for accessing metadata about sensor measurements,
/// including frame number, timestamp, and sensor transform.
///
/// All specific sensor data types (Image, LidarMeasurement, etc.) implement this trait.
/// Generic sensor data container.
///
/// This is the base type received in sensor callbacks. Use [`TryFrom`] to convert
/// to specific sensor data types like [`data::Image`](crate::sensor::data::Image),
/// [`data::LidarMeasurement`](crate::sensor::data::LidarMeasurement), etc.
///
/// # Examples
///
/// ```no_run
/// use carla::{
/// client::{ActorBase, Client},
/// sensor::{SensorDataBase, data::Image},
/// };
///
/// let client = Client::default();
/// let mut world = client.world();
///
/// // ... spawn sensor ...
/// # let bp_lib = world.blueprint_library();
/// # let camera_bp = bp_lib.filter("sensor.camera.rgb").get(0).unwrap();
/// # let spawn_points = world.map().recommended_spawn_points();
/// # let camera = world.spawn_actor(&camera_bp, &spawn_points.get(0).unwrap()).unwrap();
/// # let sensor: carla::client::Sensor = camera.try_into().unwrap();
///
/// sensor.listen(|data| {
/// // Access common metadata
/// println!("Frame: {}, Time: {:.2}s", data.frame(), data.timestamp());
///
/// // Convert to specific type
/// if let Ok(image) = Image::try_from(data) {
/// println!("Received {}x{} image", image.width(), image.height());
/// }
/// });
/// ```
assert_impl_all!;