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