Skip to content

Commit

Permalink
Enable rustfmt for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
surban committed Dec 6, 2024
1 parent f670375 commit b2eeba8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 24 deletions.
6 changes: 4 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use_small_heuristics = "Max"

fn_params_layout = "Compressed"

#wrap_comments = true
#comment_width = 100
wrap_comments = true
format_code_in_doc_comments = true
comment_width = 100

imports_granularity = "Crate"
15 changes: 11 additions & 4 deletions src/function/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ use super::{
pub struct Channel {
/// Audio channel mask. Set to 0 to disable the audio endpoint.
///
/// The audio channel mask is a bit mask of the audio channels. The mask is a 32-bit integer with each bit representing a channel. The least significant bit is channel 1. The mask is used to specify the audio channels that are present in the audio stream. For example, a stereo stream would have a mask of 0x3 (channel 1 and channel 2).
/// The audio channel mask is a bit mask of the audio channels. The mask is a 32-bit integer
/// with each bit representing a channel. The least significant bit is channel 1. The mask is
/// used to specify the audio channels that are present in the audio stream. For example, a
/// stereo stream would have a mask of 0x3 (channel 1 and channel 2).
pub channel_mask: Option<u32>,
/// Audio sample rate (Hz)
pub sample_rate: Option<u32>,
Expand All @@ -50,15 +53,18 @@ pub struct Channel {
}

impl Channel {
/// Creates a new audio channel with the specified channel mask, sample rate (Hz), and sample size (bytes).
/// Creates a new audio channel with the specified channel mask, sample rate (Hz), and sample
/// size (bytes).
pub fn new(channel_mask: u32, sample_rate: u32, sample_size: u32) -> Self {
Self { channel_mask: Some(channel_mask), sample_rate: Some(sample_rate), sample_size: Some(sample_size) }
}
}

/// Audio device configuration.
///
/// Fields are optional and will be set to f_uac2 default values if not specified, see drivers/usb/gadget/function/u_uac2.h. Not all fields are supported by all kernels; permission denied errors may occur if unsupported fields are set.
/// Fields are optional and will be set to f_uac2 default values if not specified, see
/// drivers/usb/gadget/function/u_uac2.h. Not all fields are supported by all kernels; permission
/// denied errors may occur if unsupported fields are set.
#[derive(Debug, Clone, Default)]
#[non_exhaustive]
pub struct Uac2Config {
Expand Down Expand Up @@ -281,7 +287,8 @@ impl Uac2 {
Uac2Builder::default()
}

/// Creates a new USB Audio Class 2 (UAC2) function with the specified capture and playback channels.
/// Creates a new USB Audio Class 2 (UAC2) function with the specified capture and playback
/// channels.
pub fn new(capture: Channel, playback: Channel) -> (Uac2, Handle) {
let mut builder = Uac2Builder::default();
builder.capture.channel = capture;
Expand Down
28 changes: 18 additions & 10 deletions src/function/custom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ impl OsExtProp {
// Self::new("DefaultIdleState", u32::from(state))
// }
//
// /// Indicate the amount of time in milliseconds to wait before determining that a device is idle.
// /// Indicate the amount of time in milliseconds to wait before determining that a device is
// /// idle.
// pub fn default_idle_timeout(timeout_ms: u32) -> Self {
// Self::new("DefaultIdleTimeout", timeout_ms)
// }
Expand All @@ -395,8 +396,8 @@ impl OsExtProp {
// Self::new("UserSetDeviceIdleEnabled", u32::from(enabled))
// }
//
// /// Indicate whether to allow the user to control the ability of the device to wake the system
// /// from a low-power state.
// /// Indicate whether to allow the user to control the ability of the device to wake the
// /// system from a low-power state.
// pub fn system_wake_enabled(enabled: bool) -> Self {
// Self::new("SystemWakeEnabled", u32::from(enabled))
// }
Expand Down Expand Up @@ -1613,7 +1614,8 @@ impl EndpointReceiver {

/// Receive data synchronously.
///
/// The buffer should have been allocated with the desired capacity using [`BytesMut::with_capacity`].
/// The buffer should have been allocated with the desired capacity using
/// [`BytesMut::with_capacity`].
///
/// Blocks until the operation completes and returns its result.
pub fn recv_and_fetch(&mut self, buf: BytesMut) -> Result<BytesMut> {
Expand All @@ -1623,7 +1625,8 @@ impl EndpointReceiver {

/// Receive data synchronously with a timeout.
///
/// The buffer should have been allocated with the desired capacity using [`BytesMut::with_capacity`].
/// The buffer should have been allocated with the desired capacity using
/// [`BytesMut::with_capacity`].
///
/// Blocks until the operation completes and returns its result.
pub fn recv_and_fetch_timeout(&mut self, buf: BytesMut, timeout: Duration) -> Result<BytesMut> {
Expand All @@ -1641,7 +1644,8 @@ impl EndpointReceiver {

/// Receive data.
///
/// The buffer should have been allocated with the desired capacity using [`BytesMut::with_capacity`].
/// The buffer should have been allocated with the desired capacity using
/// [`BytesMut::with_capacity`].
///
/// Waits for space in the receive queue and enqueues the buffer for receiving data.
/// Returns received data, if a buffer in the receive queue was filled.
Expand All @@ -1653,7 +1657,8 @@ impl EndpointReceiver {

/// Asynchronously receive data.
///
/// The buffer should have been allocated with the desired capacity using [`BytesMut::with_capacity`].
/// The buffer should have been allocated with the desired capacity using
/// [`BytesMut::with_capacity`].
///
/// Waits for space in the receive queue and enqueues the buffer for receiving data.
/// Returns received data, if a buffer in the receive queue was filled.
Expand All @@ -1666,7 +1671,8 @@ impl EndpointReceiver {

/// Receive data with a timeout.
///
/// The buffer should have been allocated with the desired capacity using [`BytesMut::with_capacity`].
/// The buffer should have been allocated with the desired capacity using
/// [`BytesMut::with_capacity`].
///
/// Waits for space in the receive queue and enqueues the buffer for receiving data.
/// Returns received data, if a buffer in the receive queue was filled.
Expand All @@ -1680,7 +1686,8 @@ impl EndpointReceiver {

/// Enqueue the buffer for receiving without waiting for receive queue space.
///
/// The buffer should have been allocated with the desired capacity using [`BytesMut::with_capacity`].
/// The buffer should have been allocated with the desired capacity using
/// [`BytesMut::with_capacity`].
///
/// Fails if no receive queue space is available.
pub fn try_recv(&mut self, buf: BytesMut) -> Result<()> {
Expand Down Expand Up @@ -1721,7 +1728,8 @@ impl EndpointReceiver {
Ok(Some(comp.result()?.try_into().unwrap()))
}

/// Asynchronously waits for data to be received into a previously enqueued receive buffer, then returns it.
/// Asynchronously waits for data to be received into a previously enqueued receive buffer, then
/// returns it.
///
/// `Ok(None)` is returned if no receive buffers are enqueued.
#[cfg(feature = "tokio")]
Expand Down
3 changes: 2 additions & 1 deletion src/function/msd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ impl Msd {
self.dir.status()
}

/// Forcibly detach the backing file from the LUN, regardless of whether the host has allowed it.
/// Forcibly detach the backing file from the LUN, regardless of whether the host has allowed
/// it.
pub fn force_eject(&self, lun: usize) -> Result<()> {
let lun_dir_name = Lun::dir_name(lun);
self.dir.write(format!("{lun_dir_name}/forced_eject"), "1")
Expand Down
9 changes: 6 additions & 3 deletions src/function/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
//! video.status()
//! );
//! ```
//! The gadget will bind won't enumaterate with host unless a userspace program (such as uvc-gadget) is running and responding to UVC control requests.
//! The gadget will bind won't enumaterate with host unless a userspace program (such as uvc-gadget)
//! is running and responding to UVC control requests.
use std::{
collections::HashSet,
ffi::{OsStr, OsString},
Expand All @@ -59,7 +60,8 @@ pub(crate) fn driver() -> &'static OsStr {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]
pub enum Format {
/// YUYV format [Packed YUV formats](https://docs.kernel.org/6.12/userspace-api/media/v4l/pixfmt-packed-yuv.html). Currently only uncompressed format supported.
/// YUYV format [Packed YUV formats](https://docs.kernel.org/6.12/userspace-api/media/v4l/pixfmt-packed-yuv.html).
/// Currently only uncompressed format supported.
Yuyv,
/// MJPEG compressed format.
Mjpeg,
Expand Down Expand Up @@ -197,7 +199,8 @@ pub struct UvcBuilder {
pub streaming_interval: Option<u8>,
/// bMaxBurst for super speed companion descriptor. Valid values are 1-15.
pub streaming_max_burst: Option<u8>,
/// Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. Valid values are 1024/2048/3072.
/// Maximum packet size this endpoint is capable of sending or receiving when this configuration
/// is selected. Valid values are 1024/2048/3072.
pub streaming_max_packet: Option<u32>,
/// Video device interface name
pub function_name: Option<String>,
Expand Down
3 changes: 2 additions & 1 deletion src/gadget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl Class {
Self::new(Self::VENDOR_SPECIFIC, sub_class, protocol)
}

/// Indicates that class information should be determined from the interface descriptors in the device.
/// Indicates that class information should be determined from the interface descriptors in the
/// device.
///
/// Can only be used as device class.
pub const fn interface_specific() -> Self {
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! Start defining an USB gadget by calling [`Gadget::new`].
//! When the gadget is fully specified, call [`Gadget::bind`] to register it with
//! a [USB device controller (UDC)](Udc).
//!
#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
Expand Down
6 changes: 4 additions & 2 deletions src/udc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ impl Udc {
Ok(fs::read_to_string(self.dir.join("maximum_speed"))?.trim().parse().unwrap_or_default())
}

/// Indicates that this port is the default Host on an OTG session but HNP was used to switch roles.
/// Indicates that this port is the default Host on an OTG session but HNP was used to switch
/// roles.
pub fn is_a_peripheral(&self) -> Result<bool> {
Ok(fs::read_to_string(self.dir.join("is_a_peripheral"))?.trim() != "0")
}
Expand All @@ -79,7 +80,8 @@ impl Udc {
fs::write(self.dir.join("srp"), "1")
}

/// Connect or disconnect data pull-up resistors thus causing a logical connection to or disconnection from the USB host.
/// Connect or disconnect data pull-up resistors thus causing a logical connection to or
/// disconnection from the USB host.
pub fn set_soft_connect(&self, connect: bool) -> Result<()> {
fs::write(self.dir.join("soft_connect"), if connect { "connect" } else { "disconnect" })
}
Expand Down

0 comments on commit b2eeba8

Please sign in to comment.