pub struct Convert<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C>
where T: FromBytes, C: PointConvertible<T, SIZE, DIM, METADIM>,
{ /* private fields */ }
Expand description

The Convert struct is used to convert between a PointCloud2 message and a custom type. A custom type must implement the FromBytes trait and the Into trait. The Into trait is used to convert the custom type into a tuple of the coordinates and the meta data. The FromBytes trait is used to convert the bytes from the PointCloud2 message into the custom type.

§Example

use ros_pointcloud2::mem_macros::size_of;
use ros_pointcloud2::{Convert, PointMeta};
use ros_pointcloud2::ros_types::PointCloud2Msg;
const DIM : usize = 3; // how many dimensions your point has (e.g. x, y, z)
const METADIM : usize = 4; // how many meta fields you have (e.g. r, g, b, a)
type MyConverter = Convert<f32, { size_of!(f32) }, DIM, METADIM, ([f32; DIM], [PointMeta; METADIM])>;

Implementations§

source§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> Convert<T, SIZE, DIM, METADIM, C>
where T: FromBytes, C: PointConvertible<T, SIZE, DIM, METADIM>,

source

pub fn len(&self) -> usize

Convenience getter for the number of points in the cloud.

source

pub fn is_empty(&self) -> bool

Trait Implementations§

source§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> FallibleIterator for Convert<T, SIZE, DIM, METADIM, C>
where T: FromBytes, C: PointConvertible<T, SIZE, DIM, METADIM>,

source§

fn next(&mut self) -> Result<Option<Self::Item>, Self::Error>

Iterate over the data buffer and interpret the data as a point.

§

type Item = C

The type being iterated over.
§

type Error = ConversionError

The error type.
source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns bounds on the remaining length of the iterator. Read more
source§

fn count(self) -> Result<usize, Self::Error>
where Self: Sized,

Consumes the iterator, returning the number of remaining items.
source§

fn last(self) -> Result<Option<Self::Item>, Self::Error>
where Self: Sized,

Returns the last element of the iterator.
source§

fn nth(&mut self, n: usize) -> Result<Option<Self::Item>, Self::Error>

Returns the nth element of the iterator.
source§

fn step_by(self, step: usize) -> StepBy<Self>
where Self: Sized,

Returns an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
source§

fn chain<I>(self, it: I) -> Chain<Self, I>
where I: IntoFallibleIterator<Item = Self::Item, Error = Self::Error>, Self: Sized,

Returns an iterator which yields the elements of this iterator followed by another.
source§

fn zip<I>( self, o: I ) -> Zip<Self, <I as IntoFallibleIterator>::IntoFallibleIter>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>,

Returns an iterator that yields pairs of this iterator’s and another iterator’s values.
source§

fn map<F, B>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Result<B, Self::Error>,

Returns an iterator which applies a fallible transform to the elements of the underlying iterator.
source§

fn for_each<F>(self, f: F) -> Result<(), Self::Error>
where Self: Sized, F: FnMut(Self::Item) -> Result<(), Self::Error>,

Calls a fallible closure on each element of an iterator.
source§

fn filter<F>(self, f: F) -> Filter<Self, F>
where Self: Sized, F: FnMut(&Self::Item) -> Result<bool, Self::Error>,

Returns an iterator which uses a predicate to determine which values should be yielded. The predicate may fail; such failures are passed to the caller.
source§

fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Result<Option<B>, Self::Error>,

Returns an iterator which both filters and maps. The closure may fail; such failures are passed along to the consumer.
source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Returns an iterator which yields the current iteration count as well as the value.
source§

fn peekable(self) -> Peekable<Self>
where Self: Sized,

Returns an iterator that can peek at the next element without consuming it.
source§

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> Result<bool, Self::Error>,

Returns an iterator that skips elements based on a predicate.
source§

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> Result<bool, Self::Error>,

Returns an iterator that yields elements based on a predicate.
source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Returns an iterator which skips the first n values of this iterator.
source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Returns an iterator that yields only the first n values of this iterator.
source§

fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
where Self: Sized, F: FnMut(&mut St, Self::Item) -> Result<Option<B>, Self::Error>,

Returns an iterator which applies a stateful map to values of this iterator.
source§

fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
where Self: Sized, U: IntoFallibleIterator<Error = Self::Error>, F: FnMut(Self::Item) -> Result<U, Self::Error>,

Returns an iterator which maps this iterator’s elements to iterators, yielding those iterators’ values.
source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Returns an iterator which yields this iterator’s elements and ends after the first Ok(None). Read more
source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item) -> Result<(), Self::Error>,

Returns an iterator which passes each element to a closure before returning it.
source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Borrow an iterator rather than consuming it. Read more
source§

fn collect<T>(self) -> Result<T, Self::Error>
where T: FromIterator<Self::Item>, Self: Sized,

Transforms the iterator into a collection. Read more
source§

fn partition<B, F>(self, f: F) -> Result<(B, B), Self::Error>
where Self: Sized, B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> Result<bool, Self::Error>,

Transforms the iterator into two collections, partitioning elements by a closure.
source§

fn fold<B, F>(self, init: B, f: F) -> Result<B, Self::Error>
where Self: Sized, F: FnMut(B, Self::Item) -> Result<B, Self::Error>,

Applies a function over the elements of the iterator, producing a single final value.
source§

fn try_fold<B, E, F>(&mut self, init: B, f: F) -> Result<B, E>
where Self: Sized, E: From<Self::Error>, F: FnMut(B, Self::Item) -> Result<B, E>,

Applies a function over the elements of the iterator, producing a single final value. Read more
source§

fn all<F>(&mut self, f: F) -> Result<bool, Self::Error>
where Self: Sized, F: FnMut(Self::Item) -> Result<bool, Self::Error>,

Determines if all elements of this iterator match a predicate.
source§

fn any<F>(&mut self, f: F) -> Result<bool, Self::Error>
where Self: Sized, F: FnMut(Self::Item) -> Result<bool, Self::Error>,

Determines if any element of this iterator matches a predicate.
source§

fn find<F>(&mut self, f: F) -> Result<Option<Self::Item>, Self::Error>
where Self: Sized, F: FnMut(&Self::Item) -> Result<bool, Self::Error>,

Returns the first element of the iterator that matches a predicate.
source§

fn find_map<B, F>(&mut self, f: F) -> Result<Option<B>, Self::Error>
where Self: Sized, F: FnMut(Self::Item) -> Result<Option<B>, Self::Error>,

Applies a function to the elements of the iterator, returning the first non-None result.
source§

fn position<F>(&mut self, f: F) -> Result<Option<usize>, Self::Error>
where Self: Sized, F: FnMut(Self::Item) -> Result<bool, Self::Error>,

Returns the position of the first element of this iterator that matches a predicate. The predicate may fail; such failures are returned to the caller.
source§

fn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
where Self: Sized, B: Ord, F: FnMut(&Self::Item) -> Result<B, Self::Error>,

Returns the element of the iterator which gives the maximum value from the function.
source§

fn max_by<F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Result<Ordering, Self::Error>,

Returns the element that gives the maximum value with respect to the function.
source§

fn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
where Self: Sized, B: Ord, F: FnMut(&Self::Item) -> Result<B, Self::Error>,

Returns the element of the iterator which gives the minimum value from the function.
source§

fn min_by<F>(self, f: F) -> Result<Option<Self::Item>, Self::Error>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Result<Ordering, Self::Error>,

Returns the element that gives the minimum value with respect to the function.
source§

fn unzip<A, B, FromA, FromB>(self) -> Result<(FromA, FromB), Self::Error>
where Self: Sized + FallibleIterator<Item = (A, B)>, FromA: Default + Extend<A>, FromB: Default + Extend<B>,

Converts an iterator of pairs into a pair of containers.
source§

fn cloned<'a, T>(self) -> Cloned<Self>
where Self: Sized + FallibleIterator<Item = &'a T>, T: 'a + Clone,

Returns an iterator which clones all of its elements.
source§

fn partial_cmp<I>(self, other: I) -> Result<Option<Ordering>, Self::Error>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>, Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,

Lexicographically compares the elements of this iterator to that of another.
source§

fn eq<I>(self, other: I) -> Result<bool, Self::Error>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>, Self::Item: PartialEq<<I as IntoFallibleIterator>::Item>,

Determines if the elements of this iterator are equal to those of another.
source§

fn ne<I>(self, other: I) -> Result<bool, Self::Error>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>, Self::Item: PartialEq<<I as IntoFallibleIterator>::Item>,

Determines if the elements of this iterator are not equal to those of another.
source§

fn lt<I>(self, other: I) -> Result<bool, Self::Error>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>, Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,

Determines if the elements of this iterator are lexicographically less than those of another.
source§

fn le<I>(self, other: I) -> Result<bool, Self::Error>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>, Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,

Determines if the elements of this iterator are lexicographically less than or equal to those of another.
source§

fn gt<I>(self, other: I) -> Result<bool, Self::Error>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>, Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,

Determines if the elements of this iterator are lexicographically greater than those of another.
source§

fn ge<I>(self, other: I) -> Result<bool, Self::Error>
where Self: Sized, I: IntoFallibleIterator<Error = Self::Error>, Self::Item: PartialOrd<<I as IntoFallibleIterator>::Item>,

Determines if the elements of this iterator are lexicographically greater than or equal to those of another.
source§

fn iterator(self) -> Iterator<Self>
where Self: Sized,

Returns a normal (non-fallible) iterator over Result<Item, Error>.
source§

fn map_err<B, F>(self, f: F) -> MapErr<Self, F>
where F: FnMut(Self::Error) -> B, Self: Sized,

Returns an iterator which applies a transform to the errors of the underlying iterator.
source§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryFrom<PointCloud2Msg> for Convert<T, SIZE, DIM, METADIM, C>
where T: FromBytes, C: PointConvertible<T, SIZE, DIM, METADIM>,

source§

fn try_from(cloud: PointCloud2Msg) -> Result<Self, Self::Error>

Converts a ROS PointCloud2 message into a Convert struct that implements the Iterator trait. Iterate over the struct to get or use the points.

§Example

Since we do not have a ROS node here, we first create a PointCloud2 message and then convert back to a Convert struct.

use ros_pointcloud2::ros_types::PointCloud2Msg;
use ros_pointcloud2::ConvertXYZ;
use ros_pointcloud2::pcl_utils::PointXYZ;

let cloud_points: Vec<PointXYZ> = vec![
    PointXYZ { x: 1.0, y: 2.0, z: 3.0 },
    PointXYZ { x: 4.0, y: 5.0, z: 6.0 },
];
let msg: PointCloud2Msg = ConvertXYZ::try_from(cloud_points).unwrap().try_into().unwrap();

let convert: ConvertXYZ = ConvertXYZ::try_from(msg).unwrap(); // parse message
§

type Error = ConversionError

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

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryFrom<Vec<C>> for Convert<T, SIZE, DIM, METADIM, C>
where T: FromBytes, C: PointConvertible<T, SIZE, DIM, METADIM>,

source§

fn try_from(cloud: Vec<C>) -> Result<Self, Self::Error>

Converts a vector of custom types into a Convert struct that implements the Iterator trait.

§Example
use ros_pointcloud2::{ConvertXYZ, ConversionError};
use ros_pointcloud2::pcl_utils::PointXYZ;

let cloud_points: Vec<PointXYZ> = vec![
    PointXYZ { x: 1.0, y: 2.0, z: 3.0 },
    PointXYZ { x: 4.0, y: 5.0, z: 6.0 },
];
let convert: Result<ConvertXYZ, ConversionError> = ConvertXYZ::try_from(cloud_points);
§

type Error = ConversionError

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

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> TryInto<PointCloud2Msg> for Convert<T, SIZE, DIM, METADIM, C>
where T: FromBytes, C: PointConvertible<T, SIZE, DIM, METADIM>,

source§

fn try_into(self) -> Result<PointCloud2Msg, Self::Error>

Convert the point cloud to a ROS message. First use the try_from method for initializing the conversion and parsing meta data. Then use the try_into method to do the actual conversion.

§Example
use ros_pointcloud2::ros_types::PointCloud2Msg;
use ros_pointcloud2::ConvertXYZ;
use ros_pointcloud2::pcl_utils::PointXYZ;

let cloud_points: Vec<PointXYZ> = vec![
    PointXYZ { x: 1.0, y: 2.0, z: 3.0 },
    PointXYZ { x: 4.0, y: 5.0, z: 6.0 },
];
let msg_out: PointCloud2Msg = ConvertXYZ::try_from(cloud_points).unwrap().try_into().unwrap();
§

type Error = ConversionError

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> Freeze for Convert<T, SIZE, DIM, METADIM, C>

§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> RefUnwindSafe for Convert<T, SIZE, DIM, METADIM, C>

§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> Send for Convert<T, SIZE, DIM, METADIM, C>
where C: Send, T: Send,

§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> Sync for Convert<T, SIZE, DIM, METADIM, C>
where C: Sync, T: Sync,

§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> Unpin for Convert<T, SIZE, DIM, METADIM, C>
where C: Unpin, T: Unpin,

§

impl<T, const SIZE: usize, const DIM: usize, const METADIM: usize, C> UnwindSafe for Convert<T, SIZE, DIM, METADIM, C>
where C: UnwindSafe, T: UnwindSafe,

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<I> IntoFallibleIterator for I

§

type Item = <I as FallibleIterator>::Item

The elements of the iterator.
§

type Error = <I as FallibleIterator>::Error

The error value of the iterator.
§

type IntoFallibleIter = I

The iterator.
source§

fn into_fallible_iter(self) -> I

Creates a fallible iterator from a value.
source§

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

§

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>,

§

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.