aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/macros.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2015-02-07 21:28:54 -0800
committerSteven Fackler <[email protected]>2015-02-07 21:30:05 -0800
commitec65b0c67b452539fded5e06cbb6ce1d165074e0 (patch)
treec50c22c2ce4ca095149c96a0f3a3b935b4012a5c /openssl/src/macros.rs
parentFix deprecation warnings in openssl-sys (diff)
downloadrust-openssl-ec65b0c67b452539fded5e06cbb6ce1d165074e0.tar.xz
rust-openssl-ec65b0c67b452539fded5e06cbb6ce1d165074e0.zip
Move docs to this repo and auto build
Diffstat (limited to 'openssl/src/macros.rs')
-rw-r--r--openssl/src/macros.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/openssl/src/macros.rs b/openssl/src/macros.rs
new file mode 100644
index 00000000..3e4bb429
--- /dev/null
+++ b/openssl/src/macros.rs
@@ -0,0 +1,59 @@
+#![macro_use]
+
+macro_rules! try_ssl_stream {
+ ($e:expr) => (
+ match $e {
+ Ok(ok) => ok,
+ Err(err) => return Err(StreamError(err))
+ }
+ )
+}
+
+/// Shortcut return with SSL error if something went wrong
+macro_rules! try_ssl_if {
+ ($e:expr) => (
+ if $e {
+ return Err(SslError::get())
+ }
+ )
+}
+
+/// Shortcut return with SSL error if last error result is 0
+/// (default)
+macro_rules! try_ssl{
+ ($e:expr) => (try_ssl_if!($e == 0))
+}
+
+/// Shortcut return with SSL if got a null result
+macro_rules! try_ssl_null{
+ ($e:expr) => ({
+ let t = $e;
+ try_ssl_if!(t == ptr::null_mut());
+ t
+ })
+}
+
+
+/// Lifts current SSL error code into Result<(), Error>
+/// if expression is true
+/// Lifting is actually a shortcut of the following form:
+///
+/// ```ignore
+/// let _ = try!(something)
+/// Ok(())
+/// ```
+macro_rules! lift_ssl_if{
+ ($e:expr) => ( {
+ if $e {
+ Err(SslError::get())
+ } else {
+ Ok(())
+ }
+ })
+}
+
+/// Lifts current SSL error code into Result<(), Error>
+/// if SSL returned 0 (default error indication)
+macro_rules! lift_ssl {
+ ($e:expr) => (lift_ssl_if!($e == 0))
+}