Skip to content

Commit

Permalink
Format all code with group_imports = StdExternalCrate (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnmm authored Oct 3, 2022
1 parent 956bd40 commit 3b6c013
Show file tree
Hide file tree
Showing 32 changed files with 94 additions and 77 deletions.
2 changes: 1 addition & 1 deletion examples/message_demo/src/message_demo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{Error, Result};
use std::convert::TryInto;
use std::env;

use anyhow::{Error, Result};
use rosidl_runtime_rs::{seq, BoundedSequence, Message, Sequence};

fn check_default_values() {
Expand Down
3 changes: 2 additions & 1 deletion examples/minimal_client_service/src/minimal_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Error, Result};
use std::env;

use anyhow::{Error, Result};

fn main() -> Result<(), Error> {
let context = rclrs::Context::new(env::args())?;

Expand Down
3 changes: 2 additions & 1 deletion examples/minimal_client_service/src/minimal_client_async.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Error, Result};
use std::env;

use anyhow::{Error, Result};

#[tokio::main]
async fn main() -> Result<(), Error> {
let context = rclrs::Context::new(env::args())?;
Expand Down
3 changes: 2 additions & 1 deletion examples/minimal_client_service/src/minimal_service.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Error, Result};
use std::env;

use anyhow::{Error, Result};

fn handle_service(
_request_header: &rclrs::rmw_request_id_t,
request: example_interfaces::srv::AddTwoInts_Request,
Expand Down
3 changes: 2 additions & 1 deletion examples/minimal_pub_sub/src/minimal_publisher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Error, Result};
use std::env;

use anyhow::{Error, Result};

fn main() -> Result<(), Error> {
let context = rclrs::Context::new(env::args())?;

Expand Down
3 changes: 2 additions & 1 deletion examples/minimal_pub_sub/src/minimal_subscriber.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Error, Result};
use std::env;

use anyhow::{Error, Result};

fn main() -> Result<(), Error> {
let context = rclrs::Context::new(env::args())?;

Expand Down
3 changes: 2 additions & 1 deletion examples/minimal_pub_sub/src/zero_copy_publisher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{Error, Result};
use std::env;

use anyhow::{Error, Result};

fn main() -> Result<(), Error> {
let context = rclrs::Context::new(env::args())?;

Expand Down
8 changes: 5 additions & 3 deletions rclrs/src/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::error::*;
use crate::rcl_bindings::*;
use libc::c_void;
use std::ffi::CString;
use std::os::raw::c_char;
use std::ptr::null_mut;

use libc::c_void;

use crate::error::*;
use crate::rcl_bindings::*;

/// Extract non-ROS arguments from program's input arguments.
///
/// `args` is expected to be the input arguments of the program (e.g. [`std::env::args()`]),
Expand Down
6 changes: 3 additions & 3 deletions rclrs/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use futures::channel::oneshot;
use std::boxed::Box;
use std::collections::HashMap;
use std::ffi::CString;
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex, MutexGuard};

use futures::channel::oneshot;
use rosidl_runtime_rs::Message;

use crate::error::{RclReturnCode, ToResult};
use crate::MessageCow;
use crate::Node;
use crate::{rcl_bindings::*, RclrsError};

use rosidl_runtime_rs::Message;

// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
// they are running in. Therefore, this type can be safely sent to another thread.
unsafe impl Send for rcl_client_t {}
Expand Down
6 changes: 3 additions & 3 deletions rclrs/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::rcl_bindings::*;
use crate::{RclrsError, ToResult};

use std::ffi::CString;
use std::os::raw::c_char;
use std::string::String;
use std::sync::{Arc, Mutex};
use std::vec::Vec;

use crate::rcl_bindings::*;
use crate::{RclrsError, ToResult};

impl Drop for rcl_context_t {
fn drop(&mut self) {
unsafe {
Expand Down
3 changes: 2 additions & 1 deletion rclrs/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::rcl_bindings::*;
use std::error::Error;
use std::ffi::{CStr, NulError};
use std::fmt::{self, Display};

use crate::rcl_bindings::*;

/// The main error type.
#[derive(Debug, PartialEq, Eq)]
pub enum RclrsError {
Expand Down
9 changes: 4 additions & 5 deletions rclrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ mod wait;

mod rcl_bindings;

use std::time::Duration;

pub use arguments::*;
pub use client::*;
pub use context::*;
Expand All @@ -27,15 +29,12 @@ pub use node::*;
pub use parameter::*;
pub use publisher::*;
pub use qos::*;
use rcl_bindings::rcl_context_is_valid;
pub use rcl_bindings::rmw_request_id_t;
pub use service::*;
pub use subscription::*;
pub use wait::*;

use rcl_bindings::rcl_context_is_valid;
use std::time::Duration;

pub use rcl_bindings::rmw_request_id_t;

/// Polls the node for new messages and executes the corresponding callbacks.
///
/// See [`WaitSet::wait`] for the meaning of the `timeout` parameter.
Expand Down
19 changes: 9 additions & 10 deletions rclrs/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
mod builder;
mod graph;
pub use self::builder::*;
pub use self::graph::*;

use crate::rcl_bindings::*;
use crate::{
Client, ClientBase, Context, GuardCondition, ParameterOverrideMap, Publisher, QoSProfile,
RclrsError, Service, ServiceBase, Subscription, SubscriptionBase, SubscriptionCallback,
ToResult,
};

use std::cmp::PartialEq;
use std::ffi::CStr;
use std::fmt;
Expand All @@ -19,6 +9,15 @@ use std::vec::Vec;
use libc::c_char;
use rosidl_runtime_rs::Message;

pub use self::builder::*;
pub use self::graph::*;
use crate::rcl_bindings::*;
use crate::{
Client, ClientBase, Context, GuardCondition, ParameterOverrideMap, Publisher, QoSProfile,
RclrsError, Service, ServiceBase, Subscription, SubscriptionBase, SubscriptionCallback,
ToResult,
};

impl Drop for rcl_node_t {
fn drop(&mut self) {
// SAFETY: No preconditions for this function
Expand Down
6 changes: 3 additions & 3 deletions rclrs/src/node/builder.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::ffi::CString;
use std::sync::{Arc, Mutex};

use crate::rcl_bindings::*;
use crate::{
node::call_string_getter_with_handle, resolve_parameter_overrides, Context, Node, RclrsError,
ToResult,
};

use std::ffi::CString;
use std::sync::{Arc, Mutex};

/// A builder for creating a [`Node`][1].
///
/// The builder pattern allows selectively setting some fields, and leaving all others at their default values.
Expand Down
12 changes: 8 additions & 4 deletions rclrs/src/parameter/override_map.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::rcl_bindings::*;
use crate::{ParameterValue, RclrsError, ToResult};
use libc::c_char;
use std::collections::BTreeMap;
use std::ffi::CStr;

use libc::c_char;

use crate::rcl_bindings::*;
use crate::{ParameterValue, RclrsError, ToResult};

// Internal helper struct, iterator for rcl_params_t
struct RclParamsIter<'a> {
node_name_ptrs: &'a [*mut c_char],
Expand Down Expand Up @@ -137,12 +139,14 @@ pub(crate) unsafe fn resolve_parameter_overrides(

#[cfg(test)]
mod tests {
use super::*;
use std::error::Error;
use std::ffi::CString;
use std::io::Write;

use tempfile::NamedTempFile;

use super::*;

// These files have values for every possible four-bit number, with the four bits being
// * `/**` global params
// * named global params
Expand Down
3 changes: 2 additions & 1 deletion rclrs/src/parameter/value.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::rcl_bindings::*;
use std::ffi::CStr;

use crate::rcl_bindings::*;

/// A parameter value.
///
/// Such a value can be specified in YAML format on the command line, or in a parameter file.
Expand Down
10 changes: 5 additions & 5 deletions rclrs/src/publisher.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use crate::error::{RclrsError, ToResult};
use crate::qos::QoSProfile;
use crate::rcl_bindings::*;
use crate::Node;

use std::borrow::Cow;
use std::ffi::CStr;
use std::ffi::CString;
Expand All @@ -11,6 +6,11 @@ use std::sync::{Arc, Mutex};

use rosidl_runtime_rs::{Message, RmwMessage};

use crate::error::{RclrsError, ToResult};
use crate::qos::QoSProfile;
use crate::rcl_bindings::*;
use crate::Node;

mod loaned_message;
pub use loaned_message::*;

Expand Down
6 changes: 3 additions & 3 deletions rclrs/src/publisher/loaned_message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::rcl_bindings::*;
use crate::{Publisher, RclrsError, ToResult};
use std::ops::{Deref, DerefMut};

use rosidl_runtime_rs::RmwMessage;

use std::ops::{Deref, DerefMut};
use crate::rcl_bindings::*;
use crate::{Publisher, RclrsError, ToResult};

/// A message that is owned by the middleware, loaned for publishing.
///
Expand Down
4 changes: 2 additions & 2 deletions rclrs/src/qos.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::rcl_bindings::*;

use std::time::Duration;

use crate::rcl_bindings::*;

/// The `HISTORY` DDS QoS policy.
///
/// A subscription internally maintains a queue of messages (called "samples" in DDS) that have not
Expand Down
4 changes: 2 additions & 2 deletions rclrs/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::ffi::CString;
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, Mutex, MutexGuard};

use rosidl_runtime_rs::Message;

use crate::error::{RclReturnCode, ToResult};
use crate::{rcl_bindings::*, MessageCow, Node, RclrsError};

use rosidl_runtime_rs::Message;

// SAFETY: The functions accessing this type, including drop(), shouldn't care about the thread
// they are running in. Therefore, this type can be safely sent to another thread.
unsafe impl Send for rcl_service_t {}
Expand Down
10 changes: 5 additions & 5 deletions rclrs/src/subscription.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use crate::error::{RclReturnCode, ToResult};
use crate::qos::QoSProfile;
use crate::Node;
use crate::{rcl_bindings::*, RclrsError};

use std::ffi::CStr;
use std::ffi::CString;
use std::marker::PhantomData;
Expand All @@ -11,6 +6,11 @@ use std::sync::{Arc, Mutex, MutexGuard};

use rosidl_runtime_rs::{Message, RmwMessage};

use crate::error::{RclReturnCode, ToResult};
use crate::qos::QoSProfile;
use crate::Node;
use crate::{rcl_bindings::*, RclrsError};

mod callback;
mod message_info;
mod readonly_loaned_message;
Expand Down
4 changes: 2 additions & 2 deletions rclrs/src/subscription/callback.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use rosidl_runtime_rs::Message;

use super::MessageInfo;
use crate::ReadOnlyLoanedMessage;

use rosidl_runtime_rs::Message;

/// A trait for allowed callbacks for subscriptions.
///
/// See [`AnySubscriptionCallback`] for a list of possible callback signatures.
Expand Down
4 changes: 2 additions & 2 deletions rclrs/src/subscription/message_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::rcl_bindings::*;

use std::time::{Duration, SystemTime};

use crate::rcl_bindings::*;

/// An identifier for a publisher in the local context.
///
/// To quote the `rmw` documentation:
Expand Down
6 changes: 3 additions & 3 deletions rclrs/src/subscription/readonly_loaned_message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::rcl_bindings::*;
use crate::{Subscription, ToResult};
use std::ops::Deref;

use rosidl_runtime_rs::Message;

use std::ops::Deref;
use crate::rcl_bindings::*;
use crate::{Subscription, ToResult};

/// A message that is owned by the middleware, loaned out for reading.
///
Expand Down
8 changes: 4 additions & 4 deletions rclrs/src/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
// DISTRIBUTION A. Approved for public release; distribution unlimited.
// OPSEC #4584.

use crate::error::{to_rclrs_result, RclReturnCode, RclrsError, ToResult};
use crate::rcl_bindings::*;
use crate::{ClientBase, Context, ServiceBase, SubscriptionBase};

use std::sync::{Arc, Mutex};
use std::time::Duration;
use std::vec::Vec;

use crate::error::{to_rclrs_result, RclReturnCode, RclrsError, ToResult};
use crate::rcl_bindings::*;
use crate::{ClientBase, Context, ServiceBase, SubscriptionBase};

mod exclusivity_guard;
mod guard_condition;
use exclusivity_guard::*;
Expand Down
3 changes: 2 additions & 1 deletion rclrs/src/wait/exclusivity_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ impl<T> ExclusivityGuard<T> {

#[cfg(test)]
mod tests {
use super::*;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

use super::*;

#[test]
fn test_exclusivity_guard() {
let atomic = Arc::new(AtomicBool::new(false));
Expand Down
Loading

0 comments on commit 3b6c013

Please sign in to comment.