linsight-plugin-sdk 1.20.5

Public SDK for authoring LinSight sensor plugins.
Documentation
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
// SPDX-FileCopyrightText: 2026 VisorCraft LLC
// SPDX-License-Identifier: GPL-3.0-only
//
// R-mirror types — `#[stabby::stabby]`-annotated counterparts to the
// `linsight-core` value types. These cross the plugin FFI boundary
// (vtable parameter / return slots) because std `String`, `Vec` and
// `Option` are not `IStable` and therefore cannot appear in a
// stabbified trait's vtable.
//
// **ABI v3 note on enum encoding.** Earlier versions used
// `#[stabby::stabby] #[repr(stabby)] enum` for tagged unions (RUnit,
// RReading, RCell). stabby's tagged-enum representation works
// correctly for `#[repr(u8)]` unit-only enums (RSensorKind,
// RCategory), but for enums with both unit AND payload variants the
// generated `match_owned` / `match_ref` dispatchers misroute closures
// at `opt-level >= 1`. Confirmed bug-for-bug reproducible on stabby
// 36.2.2: a Percent value round-trips to Celsius, a Scalar to
// Counter, etc. — a one-off variant misdispatch in the recursive
// Result-tree the macro emits. Debug builds pass; release builds
// silently corrupt the wire data.
//
// To eliminate the dependency on stabby's enum matcher, every former
// tagged enum is now a `(kind, payload_fields)` struct: an explicit
// `#[repr(u8)]` discriminant plus payload fields that are only valid
// when the corresponding variant is active. The host translates via
// trivial Rust `match`-on-the-kind expressions that don't rely on
// stabby-generated dispatch.
//
// This is a wire-format break vs ABI v2 — hence
// `LINSIGHT_PLUGIN_ABI_VERSION = 3` and the renamed factory symbol
// (`linsight_plugin_v3`). The daemon's version-symbol check refuses
// any v2 .so at load time.
//
// **ABI v4 note.** v4 keeps the same R-mirror encoding scheme as v3.
// The break is in `RPluginManifest` and `RSensorDescriptor`: the
// former grows `devices: SVec<RHardwareDevice>`, the latter grows
// `device_key: SOption<SString>`. The factory symbol moved to
// `linsight_plugin_v4` so v3 plugins fail symbol lookup at load
// time. See ADR-0002 and `RHardwareCategoryKind` / `RHardwareDevice`
// below.

use linsight_core::{Category, Cell, Reading, SensorId, SensorKind, TableRow, Unit};
use stabby::option::Option as SOption;
use stabby::string::String as SString;
use stabby::vec::Vec as SVec;

// ---------------------------------------------------------------------------
// RSensorId — newtype wrapper carrying a stabby String.
// ---------------------------------------------------------------------------

/// FFI-safe mirror of [`SensorId`]. Carries an opaque UTF-8 string;
/// plugins should construct via `SensorId::new(...).into()` rather than
/// touching the `value` field directly.
///
/// **Validation note:** the host runs every `RSensorId` produced by a
/// plugin through `SensorId::try_new` in [`crate::host_init`] before it
/// is allowed into the daemon's registry. A plugin that emits an empty
/// or whitespace-bearing string here is rejected with
/// [`PluginError::Parse`](crate::PluginError::Parse).
#[stabby::stabby]
#[derive(Clone, Debug)]
pub struct RSensorId {
    pub value: SString,
}

impl From<SensorId> for RSensorId {
    fn from(id: SensorId) -> Self {
        Self { value: id.as_str().into() }
    }
}

impl From<&SensorId> for RSensorId {
    fn from(id: &SensorId) -> Self {
        Self { value: id.as_str().into() }
    }
}

impl From<RSensorId> for SensorId {
    fn from(r: RSensorId) -> Self {
        SensorId::new(r.value.as_str())
    }
}

// ---------------------------------------------------------------------------
// RUnit (struct kind+payload)
// ---------------------------------------------------------------------------

/// Discriminant for [`RUnit`]. Unit-only enum, fixed `#[repr(u8)]`
/// layout; new variants are wire-format-breaking and require an ABI
/// bump.
#[stabby::stabby]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RUnitKind {
    Percent,
    Celsius,
    Bytes,
    BytesPerSec,
    Hertz,
    Watts,
    Volts,
    Rpm,
    Count,
    Custom,
}

/// FFI-safe mirror of [`Unit`]. Encoded as a `kind` discriminant plus a
/// `custom` payload that is `Some(label)` only when `kind == Custom`.
/// All other variants set `custom: None`.
#[stabby::stabby]
#[derive(Clone, Debug)]
pub struct RUnit {
    pub kind: RUnitKind,
    pub custom: SOption<SString>,
}

impl From<Unit> for RUnit {
    fn from(u: Unit) -> Self {
        match u {
            Unit::Percent => Self { kind: RUnitKind::Percent, custom: SOption::None() },
            Unit::Celsius => Self { kind: RUnitKind::Celsius, custom: SOption::None() },
            Unit::Bytes => Self { kind: RUnitKind::Bytes, custom: SOption::None() },
            Unit::BytesPerSec => Self { kind: RUnitKind::BytesPerSec, custom: SOption::None() },
            Unit::Hertz => Self { kind: RUnitKind::Hertz, custom: SOption::None() },
            Unit::Watts => Self { kind: RUnitKind::Watts, custom: SOption::None() },
            Unit::Volts => Self { kind: RUnitKind::Volts, custom: SOption::None() },
            Unit::Rpm => Self { kind: RUnitKind::Rpm, custom: SOption::None() },
            Unit::Count => Self { kind: RUnitKind::Count, custom: SOption::None() },
            Unit::Custom(s) => {
                Self { kind: RUnitKind::Custom, custom: SOption::Some(s.as_str().into()) }
            }
        }
    }
}

impl From<RUnit> for Unit {
    fn from(r: RUnit) -> Self {
        match r.kind {
            RUnitKind::Percent => Unit::Percent,
            RUnitKind::Celsius => Unit::Celsius,
            RUnitKind::Bytes => Unit::Bytes,
            RUnitKind::BytesPerSec => Unit::BytesPerSec,
            RUnitKind::Hertz => Unit::Hertz,
            RUnitKind::Watts => Unit::Watts,
            RUnitKind::Volts => Unit::Volts,
            RUnitKind::Rpm => Unit::Rpm,
            RUnitKind::Count => Unit::Count,
            RUnitKind::Custom => {
                // The wire format places the label in `custom`; an
                // empty payload here is a malformed message and we
                // surface it as an explicit fallback rather than
                // panicking at the FFI seam.
                let opt: Option<&SString> = r.custom.as_ref();
                let label = opt.map(|s| s.as_str().to_owned()).unwrap_or_default();
                Unit::Custom(label)
            }
        }
    }
}

// ---------------------------------------------------------------------------
// RSensorKind
// ---------------------------------------------------------------------------

/// FFI-safe mirror of [`SensorKind`]. Unit-only enum encoded as a single
/// byte — adding a new variant is a wire-format breaking change.
#[stabby::stabby]
#[repr(u8)]
#[derive(Clone, Copy, Debug)]
pub enum RSensorKind {
    Scalar,
    Counter,
    Table,
    State,
}

impl From<SensorKind> for RSensorKind {
    fn from(k: SensorKind) -> Self {
        match k {
            SensorKind::Scalar => RSensorKind::Scalar,
            SensorKind::Counter => RSensorKind::Counter,
            SensorKind::Table => RSensorKind::Table,
            SensorKind::State => RSensorKind::State,
        }
    }
}

impl From<RSensorKind> for SensorKind {
    fn from(r: RSensorKind) -> Self {
        match r {
            RSensorKind::Scalar => SensorKind::Scalar,
            RSensorKind::Counter => SensorKind::Counter,
            RSensorKind::Table => SensorKind::Table,
            RSensorKind::State => SensorKind::State,
        }
    }
}

// ---------------------------------------------------------------------------
// RCategory
// ---------------------------------------------------------------------------

/// FFI-safe mirror of [`Category`]. Same wire-format-stable contract as
/// [`RSensorKind`].
#[stabby::stabby]
#[repr(u8)]
#[derive(Clone, Copy, Debug)]
pub enum RCategory {
    Cpu,
    Gpu,
    Memory,
    Storage,
    Network,
    Custom,
}

impl From<Category> for RCategory {
    fn from(c: Category) -> Self {
        match c {
            Category::Cpu => RCategory::Cpu,
            Category::Gpu => RCategory::Gpu,
            Category::Memory => RCategory::Memory,
            Category::Storage => RCategory::Storage,
            Category::Network => RCategory::Network,
            Category::Custom => RCategory::Custom,
        }
    }
}

impl From<RCategory> for Category {
    fn from(r: RCategory) -> Self {
        match r {
            RCategory::Cpu => Category::Cpu,
            RCategory::Gpu => Category::Gpu,
            RCategory::Memory => Category::Memory,
            RCategory::Storage => Category::Storage,
            RCategory::Network => Category::Network,
            RCategory::Custom => Category::Custom,
        }
    }
}

// ---------------------------------------------------------------------------
// RHardwareCategoryKind
// ---------------------------------------------------------------------------

/// FFI-stable discriminant for `linsight_core::HardwareCategory`. Per
/// ADR-0001 v3 lessons, ALL discriminants are `#[repr(u8)]` unit-only
/// enums; payload-bearing variants live on a sibling struct (see
/// `RHardwareDevice`). This avoids the stabby `match_owned` release-mode
/// bug entirely.
#[stabby::stabby]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum RHardwareCategoryKind {
    Gpu,
    Storage,
    Network,
    Cpu,
    Other,
}

impl From<linsight_core::HardwareCategory> for RHardwareCategoryKind {
    fn from(c: linsight_core::HardwareCategory) -> Self {
        match c {
            linsight_core::HardwareCategory::Gpu => Self::Gpu,
            linsight_core::HardwareCategory::Storage => Self::Storage,
            linsight_core::HardwareCategory::Network => Self::Network,
            linsight_core::HardwareCategory::Cpu => Self::Cpu,
            linsight_core::HardwareCategory::Other => Self::Other,
        }
    }
}

impl From<RHardwareCategoryKind> for linsight_core::HardwareCategory {
    fn from(r: RHardwareCategoryKind) -> Self {
        match r {
            RHardwareCategoryKind::Gpu => Self::Gpu,
            RHardwareCategoryKind::Storage => Self::Storage,
            RHardwareCategoryKind::Network => Self::Network,
            RHardwareCategoryKind::Cpu => Self::Cpu,
            RHardwareCategoryKind::Other => Self::Other,
        }
    }
}

// ---------------------------------------------------------------------------
// RHardwareDevice
// ---------------------------------------------------------------------------

/// FFI-stable mirror of `linsight_core::HardwareDevice`. The plugin
/// emits these alongside its sensors; the daemon validates each one
/// before integrating into its registry.
///
/// Note: `plugin_id` and `sensor_ids` are NOT on the wire from plugin
/// to host — the daemon fills `plugin_id` from the loader's knowledge
/// and `sensor_ids` from the manifest's sensors list. Including them
/// in the FFI mirror would invite plugins to lie about either.
#[stabby::stabby]
#[repr(C)]
#[derive(Clone, Debug)]
pub struct RHardwareDevice {
    pub key: SString,
    pub category_kind: RHardwareCategoryKind,
    pub model: SString,
    pub vendor: SOption<SString>,
    pub location: SOption<SString>,
    pub plugin_device_id: SString,
}

impl From<linsight_core::HardwareDevice> for RHardwareDevice {
    fn from(d: linsight_core::HardwareDevice) -> Self {
        Self {
            key: SString::from(d.key.as_str()),
            category_kind: d.category.into(),
            model: SString::from(d.model.as_str()),
            vendor: d.vendor.map(|s| SString::from(s.as_str())).into(),
            location: d.location.map(|s| SString::from(s.as_str())).into(),
            plugin_device_id: SString::from(d.plugin_device_id.as_str()),
        }
    }
}

impl From<RHardwareDevice> for linsight_core::HardwareDevice {
    fn from(r: RHardwareDevice) -> Self {
        Self {
            key: linsight_core::HardwareDeviceKey::try_new(r.key.as_str().to_owned())
                .expect("RHardwareDevice key was validated by host_init"),
            category: r.category_kind.into(),
            model: r.model.as_str().to_owned(),
            vendor: Option::from(r.vendor).map(|s: SString| s.as_str().to_owned()),
            location: Option::from(r.location).map(|s: SString| s.as_str().to_owned()),
            plugin_id: String::new(),
            plugin_device_id: r.plugin_device_id.as_str().to_owned(),
            sensor_ids: vec![],
        }
    }
}

// ---------------------------------------------------------------------------
// RCell (struct kind+payload)
// ---------------------------------------------------------------------------

/// Discriminant for [`RCell`].
#[stabby::stabby]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RCellKind {
    Text,
    Number,
    Bytes,
}

/// FFI-safe mirror of [`Cell`] — a single cell in a Table reading.
/// Three parallel payload fields; the active one is selected by
/// `kind`. Inactive fields carry default values that are never read.
#[stabby::stabby]
#[derive(Clone, Debug)]
pub struct RCell {
    pub kind: RCellKind,
    pub text: SOption<SString>,
    pub number: f64,
    pub bytes: u64,
}

impl From<Cell> for RCell {
    fn from(c: Cell) -> Self {
        match c {
            Cell::Text(s) => Self {
                kind: RCellKind::Text,
                text: SOption::Some(s.as_str().into()),
                number: 0.0,
                bytes: 0,
            },
            Cell::Number(n) => {
                Self { kind: RCellKind::Number, text: SOption::None(), number: n, bytes: 0 }
            }
            Cell::Bytes(b) => {
                Self { kind: RCellKind::Bytes, text: SOption::None(), number: 0.0, bytes: b }
            }
        }
    }
}

impl From<RCell> for Cell {
    fn from(r: RCell) -> Self {
        match r.kind {
            RCellKind::Text => {
                let opt: Option<&SString> = r.text.as_ref();
                Cell::Text(opt.map(|s| s.as_str().to_owned()).unwrap_or_default())
            }
            RCellKind::Number => Cell::Number(r.number),
            RCellKind::Bytes => Cell::Bytes(r.bytes),
        }
    }
}

/// FFI-safe mirror of [`TableRow`] — one row of an arbitrary-width
/// [`RReading::Table`].
#[stabby::stabby]
#[derive(Clone, Debug)]
pub struct RTableRow {
    pub cells: SVec<RCell>,
}

impl From<TableRow> for RTableRow {
    fn from(row: TableRow) -> Self {
        let mut cells = SVec::with_capacity(row.cells.len());
        for c in row.cells {
            cells.push(c.into());
        }
        Self { cells }
    }
}

impl From<RTableRow> for TableRow {
    fn from(r: RTableRow) -> Self {
        TableRow { cells: svec_into_std(r.cells) }
    }
}

// ---------------------------------------------------------------------------
// RReading (struct kind+payload)
// ---------------------------------------------------------------------------

/// Discriminant for [`RReading`].
#[stabby::stabby]
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RReadingKind {
    Scalar,
    Counter,
    Table,
    State,
}

/// FFI-safe mirror of [`Reading`] — every sample a plugin returns is
/// one of these variants, selected by `kind`. The four payload fields
/// (scalar / counter / state / table) live alongside the discriminant
/// and are read individually based on `kind`. Inactive fields carry
/// defaults that callers must not read.
#[stabby::stabby]
#[derive(Clone, Debug)]
pub struct RReading {
    pub kind: RReadingKind,
    pub scalar: f64,
    pub counter: u64,
    pub state: SOption<SString>,
    pub table: SVec<RTableRow>,
}

impl From<Reading> for RReading {
    fn from(r: Reading) -> Self {
        match r {
            Reading::Scalar(v) => Self {
                kind: RReadingKind::Scalar,
                scalar: v,
                counter: 0,
                state: SOption::None(),
                table: SVec::new(),
            },
            Reading::Counter(v) => Self {
                kind: RReadingKind::Counter,
                scalar: 0.0,
                counter: v,
                state: SOption::None(),
                table: SVec::new(),
            },
            Reading::State(s) => Self {
                kind: RReadingKind::State,
                scalar: 0.0,
                counter: 0,
                state: SOption::Some(s.as_str().into()),
                table: SVec::new(),
            },
            Reading::Table(rows) => {
                let mut out = SVec::with_capacity(rows.len());
                for row in rows {
                    out.push(row.into());
                }
                Self {
                    kind: RReadingKind::Table,
                    scalar: 0.0,
                    counter: 0,
                    state: SOption::None(),
                    table: out,
                }
            }
        }
    }
}

impl From<RReading> for Reading {
    fn from(r: RReading) -> Self {
        match r.kind {
            RReadingKind::Scalar => Reading::Scalar(r.scalar),
            RReadingKind::Counter => Reading::Counter(r.counter),
            RReadingKind::State => {
                let opt: Option<&SString> = r.state.as_ref();
                Reading::State(opt.map(|s| s.as_str().to_owned()).unwrap_or_default())
            }
            RReadingKind::Table => Reading::Table(svec_into_std(r.table)),
        }
    }
}

// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------

/// Drain a `stabby::vec::Vec<R>` into a `std::vec::Vec<T>` using
/// the `From<R>` impl on `T`, preserving original order.
pub(crate) fn svec_into_std<R, T>(mut v: SVec<R>) -> Vec<T>
where
    T: From<R>,
    R: stabby::IStable + Clone,
{
    let len = v.len();
    let mut out: Vec<T> = Vec::with_capacity(len);
    while let Some(item) = v.pop() {
        out.push(T::from(item));
    }
    out.reverse();
    out
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn unit_round_trips() {
        for u in [
            Unit::Percent,
            Unit::Celsius,
            Unit::Bytes,
            Unit::BytesPerSec,
            Unit::Hertz,
            Unit::Watts,
            Unit::Volts,
            Unit::Rpm,
            Unit::Count,
            Unit::Custom("Mb/s".into()),
        ] {
            let r: RUnit = u.clone().into();
            let back: Unit = r.into();
            assert_eq!(u, back, "round trip failed for variant {u:?}");
        }
    }

    #[test]
    fn sensor_kind_round_trips() {
        for k in [SensorKind::Scalar, SensorKind::Counter, SensorKind::Table, SensorKind::State] {
            let r: RSensorKind = k.into();
            assert_eq!(SensorKind::from(r), k);
        }
    }

    #[test]
    fn category_round_trips() {
        for c in [
            Category::Cpu,
            Category::Gpu,
            Category::Memory,
            Category::Storage,
            Category::Network,
            Category::Custom,
        ] {
            let r: RCategory = c.into();
            assert_eq!(Category::from(r), c);
        }
    }

    #[test]
    fn reading_table_round_trips() {
        let r = Reading::Table(vec![TableRow {
            cells: vec![Cell::Text("p".into()), Cell::Number(1.0), Cell::Bytes(42)],
        }]);
        let rr: RReading = r.clone().into();
        let back: Reading = rr.into();
        assert_eq!(back, r);
    }

    #[test]
    fn reading_scalar_round_trips() {
        let r = Reading::Scalar(42.5);
        let rr: RReading = r.clone().into();
        assert_eq!(Reading::from(rr), r);
    }

    #[test]
    fn reading_counter_round_trips() {
        let r = Reading::Counter(123_456_789);
        let rr: RReading = r.clone().into();
        assert_eq!(Reading::from(rr), r);
    }

    #[test]
    fn reading_state_round_trips() {
        let r = Reading::State("up".into());
        let rr: RReading = r.clone().into();
        assert_eq!(Reading::from(rr), r);
    }

    #[test]
    fn sensor_id_round_trips() {
        let id = SensorId::new("cpu.util");
        let r: RSensorId = id.clone().into();
        assert_eq!(SensorId::from(r), id);
    }

    #[test]
    fn hardware_category_kind_round_trips() {
        use linsight_core::HardwareCategory;
        for c in [
            HardwareCategory::Gpu,
            HardwareCategory::Storage,
            HardwareCategory::Network,
            HardwareCategory::Cpu,
            HardwareCategory::Other,
        ] {
            let r: RHardwareCategoryKind = c.into();
            let back: HardwareCategory = r.into();
            assert_eq!(back, c);
        }
    }

    #[test]
    fn hardware_device_round_trips_minimal() {
        use linsight_core::{HardwareCategory, HardwareDevice, HardwareDeviceKey};
        let dev = HardwareDevice {
            key: HardwareDeviceKey::try_new("pci:0000:06:00.0").unwrap(),
            category: HardwareCategory::Gpu,
            model: "Intel Arc B-series".into(),
            vendor: None,
            location: None,
            plugin_id: String::new(),
            plugin_device_id: "gpu0".into(),
            sensor_ids: vec![],
        };
        let r: RHardwareDevice = dev.clone().into();
        let back: HardwareDevice = r.into();
        assert_eq!(back, dev);
    }

    #[test]
    fn hardware_device_round_trips_with_options() {
        use linsight_core::{HardwareCategory, HardwareDevice, HardwareDeviceKey};
        let dev = HardwareDevice {
            key: HardwareDeviceKey::try_new("nvml:uuid:gpu-abc").unwrap(),
            category: HardwareCategory::Gpu,
            model: "NVIDIA RTX 5080 Mobile".into(),
            vendor: Some("NVIDIA".into()),
            location: Some("PCI 0000:01:00.0".into()),
            plugin_id: String::new(),
            plugin_device_id: "gpu0".into(),
            sensor_ids: vec![],
        };
        let r: RHardwareDevice = dev.clone().into();
        let back: HardwareDevice = r.into();
        assert_eq!(back, dev);
    }
}