Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Soften generic constraint of Buffer (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
sundy-li committed Jul 12, 2022
1 parent 1d52cbf commit 6de9edf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/buffer/immutable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{iter::FromIterator, ops::Deref, sync::Arc, usize};

use crate::types::NativeType;

use super::Bytes;

/// [`Buffer`] is a contiguous memory region of plain old data types
Expand Down Expand Up @@ -34,7 +32,7 @@ use super::Bytes;
/// assert_eq!(buffer.get_mut(), None);
/// ```
#[derive(Clone)]
pub struct Buffer<T: NativeType> {
pub struct Buffer<T> {
/// the internal byte buffer.
data: Arc<Bytes<T>>,

Expand All @@ -46,27 +44,27 @@ pub struct Buffer<T: NativeType> {
length: usize,
}

impl<T: NativeType> PartialEq for Buffer<T> {
impl<T: PartialEq> PartialEq for Buffer<T> {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.deref() == other.deref()
}
}

impl<T: NativeType> std::fmt::Debug for Buffer<T> {
impl<T: std::fmt::Debug> std::fmt::Debug for Buffer<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(&**self, f)
}
}

impl<T: NativeType> Default for Buffer<T> {
impl<T> Default for Buffer<T> {
#[inline]
fn default() -> Self {
Vec::new().into()
}
}

impl<T: NativeType> Buffer<T> {
impl<T> Buffer<T> {
/// Creates an empty [`Buffer`].
#[inline]
pub fn new() -> Self {
Expand Down Expand Up @@ -169,7 +167,7 @@ impl<T: NativeType> Buffer<T> {
}
}

impl<T: NativeType> From<Vec<T>> for Buffer<T> {
impl<T> From<Vec<T>> for Buffer<T> {
#[inline]
fn from(p: Vec<T>) -> Self {
let bytes: Bytes<T> = p.into();
Expand All @@ -181,7 +179,7 @@ impl<T: NativeType> From<Vec<T>> for Buffer<T> {
}
}

impl<T: NativeType> std::ops::Deref for Buffer<T> {
impl<T> std::ops::Deref for Buffer<T> {
type Target = [T];

#[inline]
Expand All @@ -190,7 +188,7 @@ impl<T: NativeType> std::ops::Deref for Buffer<T> {
}
}

impl<T: NativeType> FromIterator<T> for Buffer<T> {
impl<T> FromIterator<T> for Buffer<T> {
#[inline]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
Vec::from_iter(iter).into()
Expand Down

0 comments on commit 6de9edf

Please sign in to comment.