Create helper Result<T> type

This commit is contained in:
Jakub Konka
2019-07-18 19:32:07 +02:00
committed by Dan Gohman
parent 08aa61f066
commit 310ecb5b5b
19 changed files with 173 additions and 255 deletions

View File

@@ -3,7 +3,7 @@
//! still largely reflects that.
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use crate::Result;
use std::{io, slice, str};
pub type void = ::std::os::raw::c_void;
@@ -499,7 +499,7 @@ pub unsafe fn iovec_to_host_mut<'a>(iovec: &'a mut __wasi_iovec_t) -> io::IoSlic
///
/// NB WASI spec requires bytes to be valid UTF-8. Otherwise,
/// `__WASI_EILSEQ` error is returned.
pub fn path_from_slice<'a>(s: &'a [u8]) -> Result<&'a str, __wasi_errno_t> {
pub fn path_from_slice<'a>(s: &'a [u8]) -> Result<&'a str> {
str::from_utf8(s).map_err(|_| __WASI_EILSEQ)
}
@@ -507,7 +507,7 @@ pub fn path_from_slice<'a>(s: &'a [u8]) -> Result<&'a str, __wasi_errno_t> {
///
/// NB WASI spec requires bytes to be valid UTF-8. Otherwise,
/// `__WASI_EILSEQ` error is returned.
pub fn path_from_vec<S: Into<Vec<u8>>>(s: S) -> Result<String, __wasi_errno_t> {
pub fn path_from_vec<S: Into<Vec<u8>>>(s: S) -> Result<String> {
String::from_utf8(s.into()).map_err(|_| __WASI_EILSEQ)
}