Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 38e9262

Browse files
Merge pull request #125 from gkoz/bytes_fix
Simplify Bytes constructor signatures to play nice with fixed-sized arrays
2 parents 1842fc3 + adc069b commit 38e9262

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/bytes.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ glib_wrapper! {
3737
}
3838

3939
impl Bytes {
40-
fn new<T: ?Sized + Borrow<[u8]>>(data: &T) -> Bytes {
41-
let data = data.borrow();
40+
/// Copies `data` into a new shared slice.
41+
fn new(data: &[u8]) -> Bytes {
4242
unsafe { from_glib_full(glib_ffi::g_bytes_new(data.as_ptr() as *const _, data.len())) }
4343
}
4444

45-
///
46-
pub fn from_static<T: ?Sized + Borrow<[u8]>>(data: &'static T) -> Bytes {
47-
let data = data.borrow();
45+
/// Creates a view into static `data` without copying.
46+
pub fn from_static(data: &'static [u8]) -> Bytes {
4847
unsafe {
4948
from_glib_full(glib_ffi::g_bytes_new_static(data.as_ptr() as *const _, data.len()))
5049
}
@@ -56,7 +55,7 @@ unsafe impl Sync for Bytes { }
5655

5756
impl<'a, T: ?Sized + Borrow<[u8]> + 'a> From<&'a T> for Bytes {
5857
fn from(value: &'a T) -> Bytes {
59-
Bytes::new(value)
58+
Bytes::new(value.borrow())
6059
}
6160
}
6261

0 commit comments

Comments
 (0)