forked from BigfootDev/flatbuffers
Rust: Fix Copy and Clone impls for a few generic types (#5577)
* Rust: Fix Copy and Clone impls for a few generic types * Add tests for Copy+Clone * Wrap Copy+Clone checks in a #[test] function
This commit is contained in:
committed by
Robert Winslow
parent
26f238c248
commit
b4774d2354
@@ -25,9 +25,19 @@ use endian_scalar::{read_scalar, read_scalar_at};
|
||||
use follow::Follow;
|
||||
use primitives::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug)]
|
||||
pub struct Vector<'a, T: 'a>(&'a [u8], usize, PhantomData<T>);
|
||||
|
||||
// We cannot use derive for these two impls, as it would only implement Copy
|
||||
// and Clone for `T: Copy` and `T: Clone` respectively. However `Vector<'a, T>`
|
||||
// can always be copied, no matter that `T` you have.
|
||||
impl<'a, T> Copy for Vector<'a, T> {}
|
||||
impl<'a, T> Clone for Vector<'a, T> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a> Vector<'a, T> {
|
||||
#[inline(always)]
|
||||
pub fn new(buf: &'a [u8], loc: usize) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user