Trait VectorElement

unsafe trait VectorElement: Sized

Trait bound for types which may be used as the T inside of a CxxVector<T> in generic code.

This trait has no publicly callable or implementable methods. Implementing it outside of the CXX codebase requires using explicit shim trait impls, adding the line impl CxxVector<MyType> {} in the same cxx::bridge that defines MyType.

Example

A bound T: VectorElement may be necessary when manipulating CxxVector in generic code.

use cxx::vector::{CxxVector, VectorElement};
use std::fmt::Display;

pub fn take_generic_vector<T>(vector: &CxxVector<T>)
where
    T: VectorElement + Display,
{
    println!("the vector elements are:");
    for element in vector {
        println!("{}", element);
    }
}

Writing the same generic function without a VectorElement trait bound would not compile.

Implementors