Skip to content

Commit 91d2a39

Browse files
committed
Refactor code
- use invalid_arg! - remove std result alias - fix getting char pointer to export_dir
1 parent bd6c354 commit 91d2a39

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/session.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::ffi::CString;
44
use std::marker;
55
use std::path::Path;
66
use std::ptr;
7-
use std::result::Result as StdResult;
87
use super::Code;
98
use super::DataType;
109
use super::Graph;
@@ -44,27 +43,23 @@ impl Session {
4443
-> Result<Self> {
4544
let mut status = Status::new();
4645

47-
let export_dir_cstr = try!(export_dir.as_ref()
48-
.to_str()
49-
.and_then(|s| CString::new(s.as_bytes()).ok())
50-
.ok_or_else(|| {
51-
Status::new_set(Code::InvalidArgument, "Invalid export directory path").unwrap()
52-
}));
46+
let export_dir_cstr =
47+
try!(export_dir.as_ref()
48+
.to_str()
49+
.and_then(|s| CString::new(s.as_bytes()).ok())
50+
.ok_or_else(|| invalid_arg!("Invalid export directory path")));
5351

5452
let tags_cstr: Vec<_> = try!(tags.into_iter()
5553
.map(|t| CString::new(t.as_ref()))
56-
.collect::<StdResult<_, _>>()
57-
.map_err(|_| {
58-
Status::new_set(Code::InvalidArgument, "Invalid tag name").unwrap()
59-
}));
54+
.collect::<::std::result::Result<_, _>>()
55+
.map_err(|_| invalid_arg!("Invalid tag name")));
6056
// keeping tags_cstr to retain strings in memory
6157
let tags_ptr: Vec<*const c_char> = tags_cstr.iter().map(|t| t.as_ptr()).collect();
6258

6359
let inner = unsafe {
6460
tf::TF_LoadSessionFromSavedModel(options.inner,
6561
ptr::null(),
66-
export_dir_cstr.to_bytes_with_nul().as_ptr() as
67-
*const c_char,
62+
export_dir_cstr.as_ptr(),
6863
tags_ptr.as_ptr(),
6964
tags_ptr.len() as c_int,
7065
graph.inner(),
@@ -351,3 +346,4 @@ mod tests {
351346
assert_eq!(data[1], 6.0);
352347
}
353348
}
349+

0 commit comments

Comments
 (0)