Lcm

Struct Lcm 

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

An LCM instance that handles publishing and subscribing, as well as encoding and decoding messages.

Implementations§

Source§

impl Lcm

Source

pub fn new() -> Result<Lcm>

Creates a new Lcm instance.

use lcm::Lcm;
let mut lcm = Lcm::new().unwrap();
Examples found in repository?
examples/publisher.rs (line 6)
4fn main()
5{
6	let mut lcm = Lcm::new().unwrap();
7	lcm.publish("example", &"Hello, World!".to_string()).unwrap();
8}
More examples
Hide additional examples
examples/subscriber.rs (line 6)
4fn main()
5{
6	let mut lcm = Lcm::new().unwrap();
7	lcm.subscribe("example", |msg: String| println!("Message: {}", msg) );
8
9	loop { lcm.handle().unwrap(); }
10}
Source

pub fn get_fileno(&self) -> c_int

Source

pub fn subscribe<M, F>( &mut self, channel: &str, callback: F, ) -> Rc<LcmSubscription>
where M: Message, F: FnMut(M) + 'static,

Subscribes a callback to a particular topic.

let mut lcm = Lcm::new().unwrap();
lcm.subscribe("GREETINGS", |name: String| println!("Hello, {}!", name) );
Examples found in repository?
examples/subscriber.rs (line 7)
4fn main()
5{
6	let mut lcm = Lcm::new().unwrap();
7	lcm.subscribe("example", |msg: String| println!("Message: {}", msg) );
8
9	loop { lcm.handle().unwrap(); }
10}
Source

pub fn unsubscribe(&mut self, handler: Rc<LcmSubscription>) -> Result<()>

Unsubscribes a message handler.

let handler = lcm.subscribe("GREETINGS", handler_function);
// ...
lcm.unsubscribe(handler);
Source

pub fn publish<M>(&mut self, channel: &str, message: &M) -> Result<()>
where M: Message,

Publishes a message on the specified channel.

let mut lcm = Lcm::new().unwrap();
lcm.publish("GREETINGS", &"Charles".to_string()).unwrap();
Examples found in repository?
examples/publisher.rs (line 7)
4fn main()
5{
6	let mut lcm = Lcm::new().unwrap();
7	lcm.publish("example", &"Hello, World!".to_string()).unwrap();
8}
Source

pub fn handle(&mut self) -> Result<()>

Waits for and dispatches the next incoming message.

let mut lcm = Lcm::new().unwrap();
lcm.subscribe("POSITION", handler_function);
loop {
    lcm.handle().unwrap();
}
Examples found in repository?
examples/subscriber.rs (line 9)
4fn main()
5{
6	let mut lcm = Lcm::new().unwrap();
7	lcm.subscribe("example", |msg: String| println!("Message: {}", msg) );
8
9	loop { lcm.handle().unwrap(); }
10}
Source

pub fn handle_timeout(&mut self, timeout: Duration) -> Result<()>

Waits for and dispatches the next incoming message, up to a time limit.

let mut lcm = Lcm::new().unwrap();
lcm.subscribe("POSITION", handler_function);
let wait_dur = Duration::from_millis(100);
loop {
    lcm.handle_timeout(Duration::from_millis(1000)).unwrap();
}
Source

pub fn subscription_set_queue_capacity( &self, handler: Rc<LcmSubscription>, num_messages: usize, )

Adjusts the maximum number of received messages that can be queued up for a subscription. The default is 30.

let handler = lcm.subscribe("POSITION", handler_function);
lcm.subscription_set_queue_capacity(handler, 30);

Trait Implementations§

Source§

impl Drop for Lcm

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Lcm

§

impl !RefUnwindSafe for Lcm

§

impl !Send for Lcm

§

impl !Sync for Lcm

§

impl Unpin for Lcm

§

impl !UnwindSafe for Lcm

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.