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;
8
9/// Extension trait for [fidl_fuchsia_ui_view::ViewRef].
10pub trait ViewRefExt {
11    /// Returns the koid (kernel object ID) for this `ViewRef`. (This involves a system call.)
12    fn get_koid(&self) -> Result<zx::Koid, zx::Status>;
13}
14
15impl ViewRefExt for ViewRef {
16    fn get_koid(&self) -> Result<zx::Koid, zx::Status> {
17        self.reference.as_handle_ref().koid()
18    }
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24    use fuchsia_scenic::ViewRefPair;
25
26    #[test]
27    fn smoke_test_get_koid() {
28        let ViewRefPair { control_ref: _control_ref, view_ref } =
29            ViewRefPair::new().expect("making ViewRefPair");
30
31        assert!(view_ref.get_koid().is_ok());
32    }
33}