Skip to main content

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        self.as_handle_ref().is_invalid()
24    }
25}
26
27impl AsPlatform for super::Rights {
28    type PlatformType = fidl::Rights;
29    fn as_platform(&self) -> Self::PlatformType {
30        fidl::Rights::from_bits_retain(self.bits())
31    }
32}
33
34impl FromPlatform<fidl::Rights> for super::Rights {
35    fn from_platform(platform_type: fidl::Rights) -> Self {
36        Self::from_bits_retain(platform_type.bits())
37    }
38}
39
40impl AsPlatform for super::ObjectType {
41    type PlatformType = fidl::ObjectType;
42    fn as_platform(&self) -> Self::PlatformType {
43        fidl::ObjectType::from_raw(*self as u32)
44    }
45}
46
47impl FromPlatform<fidl::ObjectType> for super::ObjectType {
48    fn from_platform(platform_type: fidl::ObjectType) -> Self {
49        Self::from_raw(platform_type.into_raw()).unwrap_or(Self::None)
50    }
51}
52
53impl From<fidl::HandleInfo> for super::HandleInfo {
54    fn from(handle_info: fidl::HandleInfo) -> Self {
55        Self {
56            handle: handle_info.handle.into(),
57            object_type: super::ObjectType::from_platform(handle_info.object_type),
58            rights: super::Rights::from_platform(handle_info.rights),
59        }
60    }
61}
62
63impl<'a> Into<fidl::HandleDisposition<'a>> for super::HandleDisposition {
64    fn into(self) -> fidl::HandleDisposition<'a> {
65        fidl::HandleDisposition::new(
66            fidl::HandleOp::Move(self.handle.into()),
67            self.object_type.as_platform(),
68            self.rights.as_platform(),
69            fidl::Status::OK,
70        )
71    }
72}