aboutsummaryrefslogtreecommitdiff
path: root/base/src/descriptor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/descriptor.rs')
-rw-r--r--base/src/descriptor.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/base/src/descriptor.rs b/base/src/descriptor.rs
index 2723d8e3e..0b840eae9 100644
--- a/base/src/descriptor.rs
+++ b/base/src/descriptor.rs
@@ -1,3 +1,7 @@
+// Copyright 2022 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
use crate::{PollToken, RawDescriptor};
use serde::{Deserialize, Serialize};
use std::{
@@ -24,6 +28,11 @@ pub trait AsRawDescriptor {
fn as_raw_descriptor(&self) -> RawDescriptor;
}
+/// A trait similar to `AsRawDescriptor` but supports an arbitrary number of descriptors.
+pub trait AsRawDescriptors {
+ fn as_raw_descriptors(&self) -> Vec<RawDescriptor>;
+}
+
pub trait FromRawDescriptor {
/// # Safety
/// Safe only if the caller ensures nothing has access to the descriptor after passing it to
@@ -37,6 +46,15 @@ impl AsRawDescriptor for SafeDescriptor {
}
}
+impl<T> AsRawDescriptors for T
+where
+ T: AsRawDescriptor,
+{
+ fn as_raw_descriptors(&self) -> Vec<RawDescriptor> {
+ vec![self.as_raw_descriptor()]
+ }
+}
+
impl IntoRawDescriptor for SafeDescriptor {
fn into_raw_descriptor(self) -> RawDescriptor {
let descriptor = self.descriptor;