From 8353c947b828981120757c2deecd9b0ce67dfceb Mon Sep 17 00:00:00 2001
From: Bryan Henry <bryanhenry@google.com>
Date: Thu, 2 May 2019 18:54:45 +0000
Subject: [PATCH] [fuchsia-zircon] Create fuchsia-zircon::Resource type

This just defines a new HandleBased Resource type to allow generated
Rust code for FIDL APIs that involve resources to build.
Resource-specific functions - like a wrapper for zx_resource_create -
are left for the future as needed.

Change-Id: Id43ea124258fcb29d0b7114f63175aca18176a80
---
 garnet/public/lib/fidl/rust/fidl/src/encoding.rs  |  2 ++
 garnet/public/rust/fuchsia-zircon/src/lib.rs      |  2 ++
 garnet/public/rust/fuchsia-zircon/src/resource.rs | 15 +++++++++++++++
 3 files changed, 19 insertions(+)
 create mode 100644 garnet/public/rust/fuchsia-zircon/src/resource.rs

diff --git a/garnet/public/lib/fidl/rust/fidl/src/encoding.rs b/garnet/public/lib/fidl/rust/fidl/src/encoding.rs
index ed04812c0bc..f1c2c1fb25b 100644
--- a/garnet/public/lib/fidl/rust/fidl/src/encoding.rs
+++ b/garnet/public/lib/fidl/rust/fidl/src/encoding.rs
@@ -1387,6 +1387,7 @@ type ZxInterrupt = zx::Interrupt;
 type ZxJob = zx::Job;
 type ZxLog = zx::Log;
 type ZxProcess = zx::Process;
+type ZxResource = zx::Resource;
 type ZxSocket = zx::Socket;
 type ZxThread = zx::Thread;
 type ZxTimer = zx::Timer;
@@ -1403,6 +1404,7 @@ handle_based_codable![
     ZxJob,
     ZxLog,
     ZxProcess,
+    ZxResource,
     ZxSocket,
     ZxThread,
     ZxTimer,
diff --git a/garnet/public/rust/fuchsia-zircon/src/lib.rs b/garnet/public/rust/fuchsia-zircon/src/lib.rs
index 06279813d1c..7f45e34e3e1 100644
--- a/garnet/public/rust/fuchsia-zircon/src/lib.rs
+++ b/garnet/public/rust/fuchsia-zircon/src/lib.rs
@@ -152,6 +152,7 @@ mod log;
 mod port;
 mod process;
 mod property;
+mod resource;
 mod rights;
 mod socket;
 mod signals;
@@ -175,6 +176,7 @@ pub use self::log::*;
 pub use self::port::*;
 pub use self::process::*;
 pub use self::property::*;
+pub use self::resource::*;
 pub use self::rights::*;
 pub use self::socket::*;
 pub use self::signals::*;
diff --git a/garnet/public/rust/fuchsia-zircon/src/resource.rs b/garnet/public/rust/fuchsia-zircon/src/resource.rs
new file mode 100644
index 00000000000..8224a034a03
--- /dev/null
+++ b/garnet/public/rust/fuchsia-zircon/src/resource.rs
@@ -0,0 +1,15 @@
+// Copyright 2019 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+//! Type-safe bindings for Zircon resources.
+
+use crate::{AsHandleRef, HandleBased, HandleRef, Handle};
+
+/// An object representing a Zircon resource.
+///
+/// As essentially a subtype of `Handle`, it can be freely interconverted.
+#[derive(Debug, Eq, PartialEq)]
+#[repr(transparent)]
+pub struct Resource(Handle);
+impl_handle_based!(Resource);
-- 
GitLab