@@ -15,16 +15,15 @@ use openldap::*;
15
15
use openldap :: errors :: * ;
16
16
17
17
fn some_ldap_function (ldap_uri : & str , ldap_user : & str , ldap_pass : & str ) -> Result <(), LDAPError > {
18
-
19
- let ldap = try ! (RustLDAP :: new (ldap_uri ));
18
+ let ldap = RustLDAP :: new (ldap_uri ). unwrap ();
20
19
21
20
ldap . set_option (codes :: options :: LDAP_OPT_PROTOCOL_VERSION ,
22
21
& codes :: versions :: LDAP_VERSION3 );
23
22
24
23
ldap . set_option (codes :: options :: LDAP_OPT_X_TLS_REQUIRE_CERT ,
25
24
& codes :: options :: LDAP_OPT_X_TLS_DEMAND );
26
25
27
- try ! ( ldap . simple_bind (ldap_user , ldap_pass ));
26
+ ldap . simple_bind (ldap_user , ldap_pass ). unwrap ( );
28
27
29
28
// Returns a LDAPResponse, a.k.a. Vec<HashMap<String,Vec<String>>>.
30
29
let _ = ldap . simple_search (" CN=Stephen,OU=People,DC=Earth" ,
@@ -49,22 +48,24 @@ network. See https://linux.die.net/man/3/ldap_start_tls_s for more information
49
48
50
49
``` rust
51
50
fn some_ldap_function (ldap_uri : & str , ldap_user : & str , ldap_pass : & str ) -> Result <(), LDAPError > {
52
- let ldap = try ! ( RustLDAP :: new (ldap_uri ));
51
+ let ldap = RustLDAP :: new (ldap_uri ). unwrap ( );
53
52
54
53
ldap . set_option (codes :: options :: LDAP_OPT_PROTOCOL_VERSION ,
55
54
& codes :: versions :: LDAP_VERSION3 );
56
55
57
56
ldap . set_option (codes :: options :: LDAP_OPT_X_TLS_REQUIRE_CERT ,
58
57
& codes :: options :: LDAP_OPT_X_TLS_DEMAND );
59
58
ldap . set_option (openldap :: codes :: options :: LDAP_OPT_X_TLS_NEWCTX , & 0 );
59
+
60
60
ldap . start_tls (None , None );
61
61
62
- try ! (ldap . simple_bind (ldap_user , ldap_pass ));
62
+ ldap . simple_bind (ldap_user , ldap_pass ). unwrap ();
63
+
64
+ Ok (())
63
65
}
64
66
65
67
```
66
- When performing an operation that can fail, use the ` try! ` macro. On failure,
67
- an ` openldap::errors::LDAPError ` will be returned that includes a detailed
68
+ On failure, an ` openldap::errors::LDAPError ` will be returned that includes a detailed
68
69
message from the native OpenLDAP library.
69
70
70
71
## contributing
0 commit comments