libpulse_binding/direction.rs
1// Copyright 2017 Lyndon Brown
2//
3// This file is part of the PulseAudio Rust language binding.
4//
5// Licensed under the MIT license or the Apache license (version 2.0), at your option. You may not
6// copy, modify, or distribute this file except in compliance with said license. You can find copies
7// of these licenses either in the LICENSE-MIT and LICENSE-APACHE files, or alternatively at
8// <http://opensource.org/licenses/MIT> and <http://www.apache.org/licenses/LICENSE-2.0>
9// respectively.
10//
11// Portions of documentation are copied from the LGPL 2.1+ licensed PulseAudio C headers on a
12// fair-use basis, as discussed in the overall project readme (available in the git repository).
13
14//! Utilities for direction.
15
16#[cfg(any(doc, feature = "pa_v6"))]
17use std::ffi::CStr;
18use bitflags::bitflags;
19
20bitflags! {
21 /// Flag set.
22 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
23 #[repr(transparent)]
24 pub struct FlagSet: i32 {
25 /// Output flag.
26 const OUTPUT = capi::PA_DIRECTION_OUTPUT;
27 /// Input flag.
28 const INPUT = capi::PA_DIRECTION_INPUT;
29 }
30}
31
32impl FlagSet {
33 /// Checks whether direction is valid (either input, output or bidirectional).
34 #[inline]
35 #[cfg(any(doc, feature = "pa_v6"))]
36 #[cfg_attr(docsrs, doc(cfg(feature = "pa_v6")))]
37 pub fn is_valid(self) -> bool {
38 unsafe { capi::pa_direction_valid(self.bits()) != 0 }
39 }
40
41 /// Gets a textual representation of the direction.
42 #[inline]
43 #[cfg(any(doc, feature = "pa_v6"))]
44 #[cfg_attr(docsrs, doc(cfg(feature = "pa_v6")))]
45 pub fn to_string(self) -> String {
46 unsafe {
47 CStr::from_ptr(capi::pa_direction_to_string(self.bits())).to_string_lossy().into_owned()
48 }
49 }
50}