rclrs

Struct Context

Source
pub struct Context { /* private fields */ }
Expand description

Shared state between nodes and similar entities.

It is possible, but not usually necessary, to have several contexts in an application.

Ownership of the context is shared by the Context itself and all nodes created from it.

§Details

A context stores, among other things

  • command line arguments (used for e.g. name remapping)
  • middleware-specific data, e.g. the domain participant in DDS
  • the allocator used (left as the default by rclrs)

The context also configures the rcl_logging_* layer to allow publication to /rosout (as well as the terminal). TODO: This behaviour should be configurable using an “auto logging initialise” flag as per rclcpp and rclpy.

Implementations§

Source§

impl Context

Source

pub fn new( args: impl IntoIterator<Item = String>, options: InitOptions, ) -> Result<Self, RclrsError>

Creates a new context.

  • args - A sequence of strings that resembles command line arguments that users can pass into a ROS executable. See the official tutorial to know what these arguments may look like. To simply pass in the arguments that the user has provided from the command line, call Self::from_env or Self::default_from_env instead.

  • options - Additional options that your application can use to override settings that would otherwise be determined by the environment.

Creating a context will fail if args contains invalid ROS arguments.

§Example
use rclrs::{Context, InitOptions};
let context = Context::new(
    std::env::args(),
    InitOptions::new().with_domain_id(Some(5)),
).unwrap();
assert_eq!(context.domain_id(), 5);
Source

pub fn from_env(options: InitOptions) -> Result<Self, RclrsError>

Same as Self::new but std::env::args is automatically passed in for args.

Source

pub fn default_from_env() -> Result<Self, RclrsError>

Same as Self::from_env but the default InitOptions is passed in for options.

Source

pub fn domain_id(&self) -> usize

Returns the ROS domain ID that the context is using.

The domain ID controls which nodes can send messages to each other, see the ROS 2 concept article. It can be set through the ROS_DOMAIN_ID environment variable.

Source

pub fn ok(&self) -> bool

Checks if the context is still valid.

This will return false when a signal has caused the context to shut down (currently unimplemented).

Trait Implementations§

Source§

impl CreateBasicExecutor for Context

Source§

fn create_basic_executor(&self) -> Executor

Create a basic executor associated with this Context.
Source§

impl Default for Context

Source§

fn default() -> Self

This will produce a Context without providing any command line arguments and using only the default InitOptions. This is always guaranteed to produce a valid Context instance.

This is not the same as the “default context” defined for rclcpp which is a globally shared context instance. rclrs does not offer a globally shared context instance.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.