Skip to content

Commit 5d4f613

Browse files
authored
Removed support for no_std (#109)
* Removed support for no_std * Removed more no_std dependencies * Removed more no_std dependencies * Removed more no_std dependencies * Removed downcast * Removed TryFrom, not needed with Rust 2021 * Fix visibility of modules
1 parent d2428f3 commit 5d4f613

File tree

10 files changed

+34
-82
lines changed

10 files changed

+34
-82
lines changed

rclrs/Cargo.toml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,10 @@ path = "src/lib.rs"
99

1010
[dependencies]
1111
libc = "0.2.43"
12-
lock_api = "0.4.5"
13-
cstr_core = "0.2"
14-
cty = "0.2"
15-
core-error = "0.0.0"
16-
parking_lot = {version = "0.11.2", optional = true}
17-
spin = "0.9.2"
18-
downcast = "0.10.0"
12+
parking_lot = "0.11.2"
1913

2014
[dependencies.rosidl_runtime_rs]
2115
version = "*"
2216

2317
[build-dependencies]
2418
bindgen = "0.59.1"
25-
26-
[features]
27-
default = ["std"]
28-
std = ["parking_lot"]

rclrs/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const AMENT_PREFIX_PATH: &str = "AMENT_PREFIX_PATH";
99
fn main() {
1010
let mut builder = bindgen::Builder::default()
1111
.header("src/rcl_wrapper.h")
12-
.use_core()
13-
.ctypes_prefix("cty")
1412
.derive_copy(false)
1513
.allowlist_recursively(true)
1614
.allowlist_type("rcl_.*")

rclrs/src/context.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
use crate::rcl_bindings::*;
22
use crate::{Node, RclReturnCode, ToResult};
3-
use alloc::sync::Arc;
4-
use alloc::vec::Vec;
5-
use std::string::String;
63

7-
#[cfg(not(feature = "std"))]
8-
use cstr_core::{c_char, CString};
9-
#[cfg(not(feature = "std"))]
10-
use spin::Mutex;
4+
use std::ffi::CString;
5+
use std::os::raw::c_char;
6+
use std::string::String;
7+
use std::sync::Arc;
8+
use std::vec::Vec;
119

12-
#[cfg(feature = "std")]
13-
use cty::c_char;
14-
#[cfg(feature = "std")]
1510
use parking_lot::Mutex;
16-
#[cfg(feature = "std")]
17-
use std::ffi::CString;
1811

1912
impl Drop for rcl_context_t {
2013
fn drop(&mut self) {

rclrs/src/error.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use crate::rcl_bindings::*;
2-
use core::{
3-
convert::TryFrom,
4-
fmt::{self, Display},
5-
};
6-
use core_error::{self, Error};
2+
use std::error::Error;
3+
use std::fmt::{self, Display};
74

85
/// RCL specific error codes.
96
///
@@ -615,8 +612,6 @@ impl ToResult for rcl_ret_t {
615612

616613
#[cfg(test)]
617614
mod tests {
618-
use core::convert::TryFrom;
619-
620615
use crate::error::{
621616
ClientErrorCode, EventErrorCode, LifecycleErrorCode, NodeErrorCode, ParsingErrorCode,
622617
RclErrorCode, RclReturnCode, ServiceErrorCode, SubscriberErrorCode, TimerErrorCode,

rclrs/src/lib.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
1-
#![no_std]
21
#![warn(missing_docs)]
32
//! Rust client library for ROS2.
43
//!
54
//! For getting started, see the [README][1].
65
//!
76
//! [1]: https://github.com/ros2-rust/ros2_rust/blob/master/README.md
87
9-
extern crate alloc;
10-
extern crate core_error;
11-
extern crate downcast;
8+
extern crate parking_lot;
129
extern crate rosidl_runtime_rs;
13-
14-
#[cfg(feature = "std")]
1510
extern crate std;
1611

17-
#[cfg(feature = "std")]
18-
extern crate parking_lot;
19-
20-
#[cfg(not(feature = "std"))]
21-
extern crate spin;
22-
2312
mod context;
2413
mod error;
2514
mod node;
2615
mod qos;
27-
mod rcl_bindings;
2816
mod wait;
2917

18+
mod rcl_bindings;
19+
3020
pub use context::*;
3121
pub use error::*;
3222
pub use node::*;

rclrs/src/node/mod.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
use alloc::{
2-
sync::{Arc, Weak},
3-
vec::Vec,
4-
};
5-
61
use crate::error::{RclReturnCode, ToResult};
72
use crate::qos::QoSProfile;
83
use crate::rcl_bindings::*;
94
use crate::Context;
105

11-
use rosidl_runtime_rs::Message;
12-
13-
use cstr_core::CString;
14-
156
mod publisher;
167
mod subscription;
178
pub use self::publisher::*;
189
pub use self::subscription::*;
1910

20-
#[cfg(not(feature = "std"))]
21-
use spin::Mutex;
11+
use std::ffi::CString;
12+
use std::sync::{Arc, Weak};
13+
use std::vec::Vec;
2214

23-
#[cfg(feature = "std")]
2415
use parking_lot::Mutex;
2516

17+
use rosidl_runtime_rs::Message;
18+
2619
impl Drop for rcl_node_t {
2720
fn drop(&mut self) {
2821
// SAFETY: No preconditions for this function
@@ -91,7 +84,7 @@ impl Node {
9184
Ok(Node {
9285
handle,
9386
context: context.handle.clone(),
94-
subscriptions: alloc::vec![],
87+
subscriptions: std::vec![],
9588
})
9689
}
9790

rclrs/src/node/publisher.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ use crate::error::{RclReturnCode, ToResult};
22
use crate::qos::QoSProfile;
33
use crate::rcl_bindings::*;
44
use crate::Node;
5-
use alloc::sync::Arc;
6-
use core::marker::PhantomData;
7-
use cstr_core::CString;
8-
use rosidl_runtime_rs::{Message, RmwMessage};
9-
use std::borrow::Cow;
105

11-
#[cfg(not(feature = "std"))]
12-
use spin::{Mutex, MutexGuard};
6+
use std::borrow::Cow;
7+
use std::ffi::CString;
8+
use std::marker::PhantomData;
9+
use std::sync::Arc;
1310

14-
#[cfg(feature = "std")]
1511
use parking_lot::{Mutex, MutexGuard};
1612

13+
use rosidl_runtime_rs::{Message, RmwMessage};
14+
1715
pub(crate) struct PublisherHandle {
1816
handle: Mutex<rcl_publisher_t>,
1917
node_handle: Arc<Mutex<rcl_node_t>>,
@@ -129,7 +127,7 @@ where
129127
rcl_publish(
130128
handle as *mut _,
131129
rmw_message.as_ref() as *const <T as Message>::RmwMsg as *mut _,
132-
core::ptr::null_mut(),
130+
std::ptr::null_mut(),
133131
)
134132
};
135133
ret.ok()

rclrs/src/node/subscription.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ use crate::error::{SubscriberErrorCode, ToResult};
22
use crate::qos::QoSProfile;
33
use crate::Node;
44
use crate::{rcl_bindings::*, RclReturnCode};
5-
use alloc::boxed::Box;
6-
use alloc::sync::Arc;
7-
use core::borrow::Borrow;
8-
use core::marker::PhantomData;
9-
use cstr_core::CString;
10-
use rosidl_runtime_rs::{Message, RmwMessage};
115

12-
#[cfg(not(feature = "std"))]
13-
use spin::{Mutex, MutexGuard};
6+
use std::borrow::Borrow;
7+
use std::boxed::Box;
8+
use std::ffi::CString;
9+
use std::marker::PhantomData;
10+
use std::sync::Arc;
11+
12+
use rosidl_runtime_rs::{Message, RmwMessage};
1413

15-
#[cfg(feature = "std")]
1614
use parking_lot::{Mutex, MutexGuard};
1715

1816
/// Internal struct used by subscriptions.
@@ -156,8 +154,8 @@ where
156154
rcl_take(
157155
handle as *const _,
158156
&mut rmw_message as *mut <T as Message>::RmwMsg as *mut _,
159-
core::ptr::null_mut(),
160-
core::ptr::null_mut(),
157+
std::ptr::null_mut(),
158+
std::ptr::null_mut(),
161159
)
162160
};
163161
ret.ok()?;

rclrs/src/wait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl WaitSet {
118118
rcl_wait_set_add_subscription(
119119
&mut self.handle as *mut _,
120120
&*subscription.handle().lock() as *const _,
121-
core::ptr::null_mut(),
121+
std::ptr::null_mut(),
122122
)
123123
}
124124
.ok()?;

rosidl_runtime_rs/src/string.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::cmp::Ordering;
2-
use std::convert::TryFrom;
32
use std::ffi::CStr;
43
use std::fmt::{self, Debug, Display};
54
use std::hash::{Hash, Hasher};
@@ -62,7 +61,6 @@ pub struct WString {
6261
///
6362
/// ```
6463
/// # use rosidl_runtime_rs::BoundedString;
65-
/// # use std::convert::TryFrom;
6664
/// let mut maybe_str = BoundedString::<3>::try_from("noo!");
6765
/// assert!(maybe_str.is_err());
6866
/// maybe_str = BoundedString::<3>::try_from("ok!");
@@ -85,7 +83,6 @@ pub struct BoundedString<const N: usize> {
8583
///
8684
/// ```
8785
/// # use rosidl_runtime_rs::BoundedWString;
88-
/// # use std::convert::TryFrom;
8986
/// let mut maybe_wstr = BoundedWString::<3>::try_from("noo!");
9087
/// assert!(maybe_wstr.is_err());
9188
/// maybe_wstr = BoundedWString::<3>::try_from("ok!");

0 commit comments

Comments
 (0)