Skip to content

Missing functions in rclrs #465

Open
@montmejat

Description

@montmejat

I'm simply trying to run the example from writing-your-first-rclrs-node.md but I'm getting the following errors:

error[E0425]: cannot find function `spin` in crate `rclrs`
  --> src/main.rs:29:12
   |
29 |     rclrs::spin(republisher.node)
   |            ^^^^ not found in `rclrs`

error[E0599]: no function or associated item named `new` found for struct `Node` in the current scope
   --> src/main.rs:12:33
    |
12  |         let node = rclrs::Node::new(context, "republisher")?;
    |                                 ^^^ function or associated item not found in `Node`
    |
help: there is a method `ne` with a similar name, but with different arguments
   --> /home/aurelien.montmejat/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cmp.rs:261:5
    |
261 |     fn ne(&self, other: &Rhs) -> bool {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0061]: this function takes 2 arguments but 1 argument was supplied
   --> src/main.rs:27:19
    |
27  |     let context = rclrs::Context::new(std::env::args())?;
    |                   ^^^^^^^^^^^^^^^^^^^------------------ argument #2 of type `InitOptions` is missing
    |
note: associated function defined here
   --> /home/aurelien.montmejat/ROS/workspaces/volvo/install/rclrs/share/rclrs/rust/src/context.rs:121:12
    |
121 |     pub fn new(
    |            ^^^
help: provide the argument
    |
27  |     let context = rclrs::Context::new(std::env::args(), /* InitOptions */)?;
    |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here's what I have:

use std::sync::Arc;
use std_msgs::msg::String as StringMsg;

struct RepublisherNode {
    node: Arc<rclrs::Node>,
    _subscription: Arc<rclrs::Subscription<StringMsg>>,
    data: Option<StringMsg>,
}

impl RepublisherNode {
    fn new(context: &rclrs::Context) -> Result<Self, rclrs::RclrsError> {
        let node = rclrs::Node::new(context, "republisher")?;
        let data = None;
        let _subscription =
            node.create_subscription("in_topic", rclrs::QOS_PROFILE_DEFAULT, |msg: StringMsg| {
                todo!("Assign msg to self.data")
            })?;
        Ok(Self {
            node,
            _subscription,
            data,
        })
    }
}

fn main() -> Result<(), rclrs::RclrsError> {
    let context = rclrs::Context::new(std::env::args())?;
    let republisher = RepublisherNode::new(&context)?;
    rclrs::spin(republisher.node)
}

and:

[package]
name = "..."
version = "0.1.0"
edition = "2021"

[dependencies]
rclrs = "0.4.1"
std_msgs = "*"

What could I have missed? 😅 Thanks!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions