Skip to main content

init_with_args

Function init_with_args 

Source
pub fn init_with_args<I, S>(args: I) -> Result<Context, InitError>
where I: IntoIterator<Item = S>, S: AsRef<str>,
Expand description

Pattern 3 — like init() but takes the process arguments, the way rclcpp::init(argc, argv) / rclrs’s Context::new(args, ..) do. The free-function twin of Context::new with default options.

§What it does with the arguments

It parses --ros-args with rcl’s grammar (Humble rcl/arguments.h): ROS arguments live between --ros-args and -- (or the end), several scopes may appear, and everything outside them is the program’s own and is left alone.

  • -r / --remap [node:]from:=to — honoured. The rules ride on the returned Context and are installed in every executor it creates (Context::create_executor / Context::create_executor_in) as the FALLBACK remap tier: a launch-projected rule for the same name wins (RFC-0046), exactly as rcl checks a node’s local arguments before the process’s global ones. They reach entities on every road — the handle Executor::create_node returns, nros::node! components, and the C and C++ APIs.
  • -p / --param [node:]name:=value and --params-file <path> — honoured when nros has param-services (phase-482 W5, RFC-0015 §9’s POSIX row). They ride on the Context in argv order and are applied when a node DECLARES the parameter: the last matching override wins, its text typed by the declared default, and a node: override reaches only the node of that name. The envelope, stated here because it is the API: a parameter file is read with std::fs and holds scalars only (arrays, anchors and block scalars are refused, with their line), a node key matches by NAME not namespace, and an override that does not parse as the declared type is logged and the default kept.
  • Everything else inside a scope — refused, loudly: node-identity remaps, enclaves, log flags, unknown tokens, and -p / --params-file in an image with no parameter store. Logged through nros_log, then a panic carrying REFUSE_INIT_ARGS and the argument. rclcpp refuses unknown ROS arguments too (UnknownROSArgsError).

§Where the rules do NOT reach

Context::config refuses a context that carries rules, because an ExecutorConfig cannot carry them. Entities created through the executor’s own add_* registration methods or a node_mut context are not remapped either: those are also where the C ABI and the component sink hand their ALREADY-RESOLVED names, so remapping there would apply a rule twice.