[librsvg] Reference::parse(): Return a ReferenceError, not a ()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Reference::parse(): Return a ReferenceError, not a ()
- Date: Thu, 29 Nov 2018 18:04:49 +0000 (UTC)
commit 061dc4cf55e7cec03f745ec2473ee30f80507ead
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Nov 28 12:04:01 2018 -0600
Reference::parse(): Return a ReferenceError, not a ()
rsvg_internals/src/defs.rs | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index 881da292..aef34c0f 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -82,8 +82,13 @@ pub enum Reference {
UriWithFragmentId(String, String),
}
+#[derive(Debug, PartialEq)]
+pub enum ReferenceError {
+ ParseError,
+}
+
impl Reference {
- pub fn parse(s: &str) -> Result<Reference, ()> {
+ pub fn parse(s: &str) -> Result<Reference, ReferenceError> {
let (uri, fragment) = match s.rfind('#') {
None => (Some(s), None),
Some(p) if p == 0 => (None, Some(&s[1..])),
@@ -91,13 +96,13 @@ impl Reference {
};
match (uri, fragment) {
- (None, Some(f)) if f.len() == 0 => Err(()),
+ (None, Some(f)) if f.len() == 0 => Err(ReferenceError::ParseError),
(None, Some(f)) => Ok(Reference::FragmentId(f.to_string())),
- (Some(u), _) if u.len() == 0 => Err(()),
+ (Some(u), _) if u.len() == 0 => Err(ReferenceError::ParseError),
(Some(u), None) => Ok(Reference::PlainUri(u.to_string())),
- (Some(_u), Some(f)) if f.len() == 0 => Err(()),
+ (Some(_u), Some(f)) if f.len() == 0 => Err(ReferenceError::ParseError),
(Some(u), Some(f)) => Ok(Reference::UriWithFragmentId(u.to_string(), f.to_string())),
- (_, _) => Err(()),
+ (_, _) => Err(ReferenceError::ParseError),
}
}
}
@@ -149,8 +154,8 @@ mod tests {
#[test]
fn reference_errors() {
- assert!(Reference::parse("").is_err());
- assert!(Reference::parse("#").is_err());
- assert!(Reference::parse("uri#").is_err());
+ assert_eq!(Reference::parse(""), Err(ReferenceError::ParseError));
+ assert_eq!(Reference::parse("#"), Err(ReferenceError::ParseError));
+ assert_eq!(Reference::parse("uri#"), Err(ReferenceError::ParseError));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]