Buffer::from_slice() / from_mut_slice() can't possibly return None

This commit is contained in:
Sebastian Dröge 2018-12-26 08:50:44 +01:00
parent d257ece388
commit 005f436631
5 changed files with 15 additions and 15 deletions

View file

@ -72,7 +72,7 @@ impl Buffer {
drop(slice);
}
pub fn from_mut_slice<T: AsMut<[u8]> + Send + 'static>(slice: T) -> Option<Self> {
pub fn from_mut_slice<T: AsMut<[u8]> + Send + 'static>(slice: T) -> Self {
assert_initialized_main_thread!();
unsafe {
@ -94,7 +94,7 @@ impl Buffer {
}
}
pub fn from_slice<T: AsRef<[u8]> + Send + 'static>(slice: T) -> Option<Self> {
pub fn from_slice<T: AsRef<[u8]> + Send + 'static>(slice: T) -> Self {
assert_initialized_main_thread!();
unsafe {
@ -684,7 +684,7 @@ mod tests {
fn test_writability() {
::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let data = buffer.map_readable().unwrap();
assert_eq!(data.as_slice(), vec![1, 2, 3, 4].as_slice());

View file

@ -57,7 +57,7 @@ struct BufferDe {
impl From<BufferDe> for Buffer {
fn from(buf_de: BufferDe) -> Self {
let mut buffer = Buffer::from_mut_slice(buf_de.buffer.to_vec()).unwrap();
let mut buffer = Buffer::from_mut_slice(buf_de.buffer.to_vec());
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(buf_de.pts);
@ -90,7 +90,7 @@ mod tests {
fn test_serialize() {
::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(1.into());
@ -230,7 +230,7 @@ mod tests {
fn test_serde_roundtrip() {
::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(1.into());

View file

@ -80,7 +80,7 @@ mod tests {
{
let buffer_list = buffer_list.get_mut().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(1.into());
@ -90,7 +90,7 @@ mod tests {
}
buffer_list.add(buffer);
let mut buffer = Buffer::from_slice(vec![5, 6]).unwrap();
let mut buffer = Buffer::from_slice(vec![5, 6]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(5.into());
@ -196,7 +196,7 @@ mod tests {
{
let buffer_list = buffer_list.get_mut().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(1.into());
@ -206,7 +206,7 @@ mod tests {
}
buffer_list.add(buffer);
let mut buffer = Buffer::from_slice(vec![5, 6]).unwrap();
let mut buffer = Buffer::from_slice(vec![5, 6]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(5.into());

View file

@ -93,7 +93,7 @@ mod tests {
pretty_config.new_line = "".to_string();
let sample = {
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(1.into());
@ -179,7 +179,7 @@ mod tests {
);
let sample = {
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(1.into());
@ -323,7 +323,7 @@ mod tests {
// Segment present
let sample = {
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_pts(1.into());

View file

@ -270,7 +270,7 @@ mod tests {
tags.add::<DateTime>(&::DateTime::new_ymd(2018, 5, 28), TagMergeMode::Append);
let sample = {
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_offset(0);
@ -452,7 +452,7 @@ mod tests {
tags.add::<DateTime>(&::DateTime::new_ymd(2018, 5, 28), TagMergeMode::Append);
let sample = {
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]).unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
let buffer = buffer.get_mut().unwrap();
buffer.set_offset(0);