Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 35cc4ca

Browse files
committed
Fixed error handling for bool specilization of constant trait
1 parent 21fc3e6 commit 35cc4ca

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

‎src/data/mod.rs‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,16 @@ impl ConstGenerator for Complex<f64> {
133133

134134
#[allow(unused_mut)]
135135
impl ConstGenerator for bool {
136-
fn generate(&self, dims: Dim4) -> Array {
136+
fn generate(&self, dims: Dim4) -> Result<Array,AfError> {
137137
unsafe {
138138
let mut temp: i64 = 0;
139-
af_constant(&mut temp as MutAfArray, *self as c_int as c_double,
140-
dims.ndims() as c_uint, dims.get().as_ptr() as *const DimT, 4);
141-
Array::from(temp)
139+
let err_val = af_constant(&mut temp as MutAfArray, *self as c_int as c_double,
140+
dims.ndims() as c_uint,
141+
dims.get().as_ptr() as *const DimT, 4);
142+
match err_val {
143+
0 => Ok(Array::from(temp)),
144+
_ => Err(AfError::from(err_val)),
145+
}
142146
}
143147
}
144148
}

‎src/graphics.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
extern crate libc;
2+
3+
use defines::AfError;
4+
use defines::Aftype;
5+
use self::libc::{uint8_t, c_int, c_uint, c_double};
6+
7+
type MutWindow = *mut self::libc::c_ulonglong;
8+
type Window = self::libc::c_ulonglong;
9+
type AfArray = self::libc::c_longlong;
10+
type Cell = *const self::libc::c_void;
11+
12+
#[allow(dead_code)]
13+
extern {
14+
fn af_create_window(out: MutWindow, w: c_int, h: c_int, title: *const u8) -> c_int;
15+
fn af_set_position(wnd: Window, x: c_uint, y: c_uint) -> c_int;
16+
fn af_set_title(wnd: Window, title: *const u8) -> c_int;
17+
fn af_draw_image(wnd: Window, arr: AfArray, props: Cell) -> c_int;
18+
fn af_draw_plot(wnd: Window, x: AfArray, y: AfArray, props: Cell) -> c_int;
19+
fn af_grid(wnd: Window, rows: c_int, cols: c_int) -> c_int;
20+
fn af_show(wnd: Window) -> c_int;
21+
fn af_is_window_closed(out: *mut c_int, wnd: Window) -> c_int;
22+
fn af_destroy_window(wnd: Window) -> c_int;
23+
24+
fn af_draw_hist(wnd: Window, x: AfArray,
25+
minval: c_double, maxval: c_double, props: Cell) -> c_int;
26+
}

‎src/lib.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ mod defines;
4040
pub use dim4::Dim4;
4141
mod dim4;
4242

43+
pub use graphics::Window;
44+
mod graphics;
45+
4346
pub use image::{gaussian_kernel, load_image, save_image};
4447
pub use image::{resize, transform, rotate, translate, scale, skew};
4548
pub use image::{dilate, dilate3, erode, erode3, minfilt, maxfilt};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /