[librsvg: 6/38] Use expect() instead of unreachable() for the property value checks
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 6/38] Use expect() instead of unreachable() for the property value checks
- Date: Fri, 25 Jan 2019 19:37:52 +0000 (UTC)
commit 25910640924d2336502b61b8f86cd8b504885311
Author: Federico Mena Quintero <federico gnome org>
Date: Thu Jan 17 08:36:12 2019 -0600
Use expect() instead of unreachable() for the property value checks
rsvg_internals/src/c_api.rs | 125 +++++++++++++------------------------------
rsvg_internals/src/handle.rs | 2 +-
2 files changed, 39 insertions(+), 88 deletions(-)
---
diff --git a/rsvg_internals/src/c_api.rs b/rsvg_internals/src/c_api.rs
index e1930ebc..23ce1fb9 100644
--- a/rsvg_internals/src/c_api.rs
+++ b/rsvg_internals/src/c_api.rs
@@ -1,12 +1,12 @@
-use std::{i32, f64};
use std::ops;
+use std::{f64, i32};
-use glib::{ParamSpec, ParamFlags};
use glib::object::ObjectClass;
use glib::subclass;
-use glib::subclass::prelude::*;
use glib::subclass::object::ObjectClassSubclassExt;
+use glib::subclass::prelude::*;
use glib::translate::*;
+use glib::{ParamFlags, ParamSpec};
use glib_sys;
use gobject_sys;
@@ -41,7 +41,6 @@ unsafe impl InstanceStruct for RsvgHandle {
type Type = Handle;
}
-
impl ops::Deref for RsvgHandleClass {
type Target = ObjectClass;
@@ -67,27 +66,28 @@ static PROPERTIES: [subclass::Property; 11] = [
ParamFlags::READWRITE | ParamFlags::CONSTRUCT_ONLY,
)
}),
-
subclass::Property("dpi-x", |name| {
ParamSpec::double(
name,
"Horizontal DPI",
"Horizontal resolution in dots per inch",
- 0.0, f64::MAX, 0.0,
+ 0.0,
+ f64::MAX,
+ 0.0,
ParamFlags::READWRITE | ParamFlags::CONSTRUCT,
)
}),
-
subclass::Property("dpi-y", |name| {
ParamSpec::double(
name,
"Vertical DPI",
"Vertical resolution in dots per inch",
- 0.0, f64::MAX, 0.0,
+ 0.0,
+ f64::MAX,
+ 0.0,
ParamFlags::READWRITE | ParamFlags::CONSTRUCT,
)
}),
-
subclass::Property("base-uri", |name| {
ParamSpec::string(
name,
@@ -97,75 +97,42 @@ static PROPERTIES: [subclass::Property; 11] = [
ParamFlags::READWRITE | ParamFlags::CONSTRUCT,
)
}),
-
subclass::Property("width", |name| {
ParamSpec::int(
name,
"Image width",
"Image width",
- 0, i32::MAX, 0,
+ 0,
+ i32::MAX,
+ 0,
ParamFlags::READABLE,
)
}),
-
subclass::Property("height", |name| {
ParamSpec::int(
name,
"Image height",
"Image height",
- 0, i32::MAX, 0,
+ 0,
+ i32::MAX,
+ 0,
ParamFlags::READABLE,
)
}),
-
subclass::Property("em", |name| {
- ParamSpec::double(
- name,
- "em",
- "em",
- 0.0, f64::MAX, 0.0,
- ParamFlags::READABLE,
- )
+ ParamSpec::double(name, "em", "em", 0.0, f64::MAX, 0.0, ParamFlags::READABLE)
}),
-
subclass::Property("ex", |name| {
- ParamSpec::double(
- name,
- "ex",
- "ex",
- 0.0, f64::MAX, 0.0,
- ParamFlags::READABLE,
- )
+ ParamSpec::double(name, "ex", "ex", 0.0, f64::MAX, 0.0, ParamFlags::READABLE)
}),
-
subclass::Property("title", |name| {
- ParamSpec::string(
- name,
- "deprecated",
- "deprecated",
- None,
- ParamFlags::READABLE,
- )
+ ParamSpec::string(name, "deprecated", "deprecated", None, ParamFlags::READABLE)
}),
-
subclass::Property("desc", |name| {
- ParamSpec::string(
- name,
- "deprecated",
- "deprecated",
- None,
- ParamFlags::READABLE,
- )
+ ParamSpec::string(name, "deprecated", "deprecated", None, ParamFlags::READABLE)
}),
-
subclass::Property("metadata", |name| {
- ParamSpec::string(
- name,
- "deprecated",
- "deprecated",
- None,
- ParamFlags::READABLE,
- )
+ ParamSpec::string(name, "deprecated", "deprecated", None, ParamFlags::READABLE)
}),
];
@@ -177,7 +144,7 @@ impl ObjectSubclass for Handle {
// We don't use subclass:simple::InstanceStruct and ClassStruct
// because we need to maintain the respective _abi_padding of each
// of RsvgHandleClass and RsvgHandle.
-
+
type Instance = RsvgHandle;
type Class = RsvgHandleClass;
@@ -187,7 +154,7 @@ impl ObjectSubclass for Handle {
klass.install_properties(&PROPERTIES);
}
- fn new_with_class(_klass: &Self::Class) -> Self {
+ fn new() -> Self {
Handle::new()
}
}
@@ -200,35 +167,19 @@ impl ObjectImpl for Handle {
match *prop {
subclass::Property("flags", ..) => {
- if let Some(v) = value.get() {
- self.set_load_flags(v);
- } else {
- unreachable!("flags value has incorrect type");
- }
+ self.set_load_flags(value.get().expect("flags value has incorrect type"));
}
subclass::Property("dpi-x", ..) => {
- if let Some(v) = value.get() {
- self.set_dpi_x(v);
- } else {
- unreachable!("dpi-x value has incorrect type");
- }
+ self.set_dpi_x(value.get().expect("dpi-x value has incorrect type"));
}
subclass::Property("dpi-y", ..) => {
- if let Some(v) = value.get() {
- self.set_dpi_y(v);
- } else {
- unreachable!("dpi-y value has incorrect type");
- }
+ self.set_dpi_y(value.get().expect("dpi-y value has incorrect type"));
}
subclass::Property("base-uri", ..) => {
- if let Some(url) = value.get() {
- self.set_base_url(url);
- } else {
- unreachable!("base-uri should be a non-NULL string");
- }
+ self.set_base_url(value.get().expect("base-uri should be a non-NULL string"));
}
_ => unimplemented!("invalid property id {}", id),
@@ -236,21 +187,21 @@ impl ObjectImpl for Handle {
}
fn get_property(&self, _obj: &glib::Object, id: usize) -> Result<glib::Value, ()> {
-// let prop = &PROPERTIES[id];
-//
-// match *prop {
-// subclass::Property("name", ..) => Ok(self.name.borrow().to_value()),
-// _ => unimplemented!(),
-// }
+ // let prop = &PROPERTIES[id];
+ //
+ // match *prop {
+ // subclass::Property("name", ..) => Ok(self.name.borrow().to_value()),
+ // _ => unimplemented!(),
+ // }
unimplemented!();
}
-
+
fn constructed(&self, obj: &glib::Object) {
-// // Chain up to the parent type's implementation of this virtual
-// // method.
-// self.parent_constructed(obj);
-//
-// // And here we could do our own initialization.
+ // // Chain up to the parent type's implementation of this virtual
+ // // method.
+ // self.parent_constructed(obj);
+ //
+ // // And here we could do our own initialization.
unimplemented!();
}
}
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 9a3be586..95cde58c 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -157,7 +157,7 @@ pub struct Handle {
}
impl Handle {
- fn new() -> Handle {
+ pub fn new() -> Handle {
Handle {
dpi: Cell::new(Dpi::default()),
base_url: RefCell::new(None),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]