fidl_fuchsia_ui_views_ext/
lib.rs

1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Extensions for `fidl_fuchsia_ui_view`.
6
7use fidl_fuchsia_ui_views::ViewRef;
8use zx::{self as zx, AsHandleRef};
9
10/// Extension trait for [fidl_fuchsia_ui_view::ViewRef].
11pub trait ViewRefExt {
12    /// Returns the koid (kernel object ID) for this `ViewRef`. (This involves a system call.)
13    fn get_koid(&self) -> Result<zx::Koid, zx::Status>;
14}
15
16impl ViewRefExt for ViewRef {
17    fn get_koid(&self) -> Result<zx::Koid, zx::Status> {
18        self.reference.as_handle_ref().get_koid()
19    }
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25    use fuchsia_scenic::ViewRefPair;
26
27    #[test]
28    fn smoke_test_get_koid() {
29        let ViewRefPair { control_ref: _control_ref, view_ref } =
30            ViewRefPair::new().expect("making ViewRefPair");
31
32        assert!(view_ref.get_koid().is_ok());
33    }
34}