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
)
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(args: impl IntoIterator<Item = String>) -> Result<Self, RclrsError>
pub fn new(args: impl IntoIterator<Item = String>) -> Result<Self, RclrsError>
Creates a new context.
Usually, this would be called with std::env::args()
, analogously to rclcpp::init()
.
See also the official “Passing ROS arguments to nodes via the command-line” tutorial.
Creating a context can fail in case the args contain invalid ROS arguments.
§Example
assert!(Context::new([]).is_ok());
let invalid_remapping = ["--ros-args", "-r", ":=:*/]"].map(String::from);
assert!(Context::new(invalid_remapping).is_err());
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more