fidl_codec/handle/
classic.rs

1// Copyright 2025 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
5use super::{AsPlatform, FromPlatform};
6
7pub use fidl::{Channel, NullableHandle};
8
9impl super::CodecHandle for NullableHandle {
10    type Channel = Channel;
11    fn invalid() -> Self {
12        Self::invalid()
13    }
14
15    fn as_raw(&self) -> u32 {
16        self.as_handle_ref().raw_handle()
17    }
18}
19
20impl super::CodecChannel for Channel {
21    type Handle = NullableHandle;
22    fn is_invalid(&self) -> bool {
23        #[cfg(not(target_os = "fuchsia"))]
24        use fidl::AsHandleRef;
25        self.as_handle_ref().is_invalid()
26    }
27}
28
29impl AsPlatform for super::Rights {
30    type PlatformType = fidl::Rights;
31    fn as_platform(&self) -> Self::PlatformType {
32        fidl::Rights::from_bits_retain(self.bits())
33    }
34}
35
36impl FromPlatform<fidl::Rights> for super::Rights {
37    fn from_platform(platform_type: fidl::Rights) -> Self {
38        Self::from_bits_retain(platform_type.bits())
39    }
40}
41
42impl AsPlatform for super::ObjectType {
43    type PlatformType = fidl::ObjectType;
44    fn as_platform(&self) -> Self::PlatformType {
45        fidl::ObjectType::from_raw(*self as u32)
46    }
47}
48
49impl FromPlatform<fidl::ObjectType> for super::ObjectType {
50    fn from_platform(platform_type: fidl::ObjectType) -> Self {
51        Self::from_raw(platform_type.into_raw()).unwrap_or(Self::None)
52    }
53}
54
55impl From<fidl::HandleInfo> for super::HandleInfo {
56    fn from(handle_info: fidl::HandleInfo) -> Self {
57        Self {
58            handle: handle_info.handle.into(),
59            object_type: super::ObjectType::from_platform(handle_info.object_type),
60            rights: super::Rights::from_platform(handle_info.rights),
61        }
62    }
63}
64
65impl<'a> Into<fidl::HandleDisposition<'a>> for super::HandleDisposition {
66    fn into(self) -> fidl::HandleDisposition<'a> {
67        fidl::HandleDisposition::new(
68            fidl::HandleOp::Move(self.handle.into()),
69            self.object_type.as_platform(),
70            self.rights.as_platform(),
71            fidl::Status::OK,
72        )
73    }
74}