Skip to content

Commit d062a92

Browse files
author
Elrendio
committed
fix lib doc
1 parent 865745b commit d062a92

File tree

3 files changed

+51
-41
lines changed

3 files changed

+51
-41
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ openssl = { version = "0.10", optional = true }
3434
[dependencies.native-tls]
3535
version = "0.2"
3636
optional = true
37+
38+
[package.metadata.docs.rs]
39+
rustc-args = ["--cfg", "secure"]

src/ftp.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl FtpStream {
226226
/// let mut ctx = SslContext::builder(SslMethod::tls()).unwrap();
227227
/// let _ = ctx.set_ca_file(Path::new("/path/to/a/cert.pem")).unwrap();
228228
/// let ctx = ctx.build();
229-
/// let mut ftp_stream = FtpStream::connect("127.0.0.1:21").unwrap();
229+
/// let (mut ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap();
230230
/// let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap();
231231
/// // Do all secret things
232232
/// // Switch back to the insecure mode
@@ -301,7 +301,7 @@ impl FtpStream {
301301
/// use ftp::FtpStream;
302302
/// use std::time::Duration;
303303
///
304-
/// let stream = FtpStream::connect("127.0.0.1:21")
304+
/// let (stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21")
305305
/// .expect("Couldn't connect to the server...");
306306
/// stream.get_ref().set_read_timeout(Some(Duration::from_secs(10)))
307307
/// .expect("set_read_timeout call failed");
@@ -432,7 +432,7 @@ impl FtpStream {
432432
/// ```
433433
/// # use ftp::{FtpStream, FtpError};
434434
/// # use std::io::Cursor;
435-
/// # let mut conn = FtpStream::connect("127.0.0.1:21").unwrap();
435+
/// # let (mut conn, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap();
436436
/// # conn.login("Doe", "mumble").and_then(|_| {
437437
/// # let mut reader = Cursor::new("hello, world!".as_bytes());
438438
/// # conn.put("retr.txt", &mut reader)
@@ -469,7 +469,7 @@ impl FtpStream {
469469
/// ```
470470
/// # use ftp::{FtpStream, FtpError};
471471
/// # use std::io::Cursor;
472-
/// # let mut conn = FtpStream::connect("127.0.0.1:21").unwrap();
472+
/// # let (mut conn, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap();
473473
/// # conn.login("Doe", "mumble").and_then(|_| {
474474
/// # let mut reader = Cursor::new("hello, world!".as_bytes());
475475
/// # conn.put("simple_retr.txt", &mut reader)

src/lib.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//!
1010
//! ```rust
1111
//! use ftp::FtpStream;
12-
//! let mut (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap_or_else(|err|
12+
//! let (mut ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap_or_else(|err|
1313
//! panic!("{}", err)
1414
//! );
1515
//! let _ = ftp_stream.quit();
@@ -28,43 +28,50 @@
2828
//! For better security it's the good practice to switch to the secure mode
2929
//! before authentication.
3030
//!
31-
//! ## FTPS Usage
32-
//!
33-
//! ```rust,no_run
34-
//! use ftp::FtpStream;
35-
//! use ftp::openssl::ssl::{ SslContext, SslMethod };
36-
//!
37-
//! let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap();
38-
//! let ctx = SslContext::builder(SslMethod::tls()).unwrap().build();
39-
//! // Switch to the secure mode
40-
//! let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap();
41-
//! ftp_stream.login("anonymous", "anonymous").unwrap();
42-
//! // Do other secret stuff
43-
//! // Switch back to the insecure mode (if required)
44-
//! let mut ftp_stream = ftp_stream.into_insecure().unwrap();
45-
//! // Do all public stuff
46-
//! let _ = ftp_stream.quit();
47-
//! ```
48-
//!
49-
//! ## FTPS Usage with native-tls
50-
//!
51-
//! ```rust,no_run
52-
//! use ftp::FtpStream;
53-
//! use ftp::native_tls::{TlsConnector, TlsStream};
54-
//!
55-
//! let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap();
56-
//! let mut ctx = TlsConnector::new().unwrap();
57-
//! // Switch to the secure mode
58-
//! let mut ftp_stream = ftp_stream.into_secure(ctx, "localhost").unwrap();
59-
//! ftp_stream.login("anonymous", "anonymous").unwrap();
60-
//! // Do other secret stuff
61-
//! // Switch back to the insecure mode (if required)
62-
//! let mut ftp_stream = ftp_stream.into_insecure().unwrap();
63-
//! // Do all public stuff
64-
//! let _ = ftp_stream.quit();
65-
//! ```
66-
//!
31+
#![cfg_attr(
32+
all(feature = "secure", not(feature = "native-tls")),
33+
doc = r##"
34+
## FTPS Usage
35+
36+
```rust,no_run
37+
use ftp::FtpStream;
38+
use ftp::openssl::ssl::{ SslContext, SslMethod };
39+
40+
let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap();
41+
let ctx = SslContext::builder(SslMethod::tls()).unwrap().build();
42+
// Switch to the secure mode
43+
let mut ftp_stream = ftp_stream.into_secure(ctx).unwrap();
44+
ftp_stream.login("anonymous", "anonymous").unwrap();
45+
// Do other secret stuff
46+
// Switch back to the insecure mode (if required)
47+
let mut ftp_stream = ftp_stream.into_insecure().unwrap();
48+
// Do all public stuff
49+
let _ = ftp_stream.quit();
50+
```
51+
"##
52+
)]
53+
#![cfg_attr(
54+
all(feature = "secure", feature = "native-tls"),
55+
doc = r##"
56+
## FTPS Usage
57+
58+
```rust,no_run
59+
use ftp::FtpStream;
60+
use ftp::native_tls::{TlsConnector, TlsStream};
6761
62+
let (ftp_stream, _welcome_msg) = FtpStream::connect("127.0.0.1:21").unwrap();
63+
let mut ctx = TlsConnector::new().unwrap();
64+
// Switch to the secure mode
65+
let mut ftp_stream = ftp_stream.into_secure(ctx, "localhost").unwrap();
66+
ftp_stream.login("anonymous", "anonymous").unwrap();
67+
// Do other secret stuff
68+
// Switch back to the insecure mode (if required)
69+
let mut ftp_stream = ftp_stream.into_insecure().unwrap();
70+
// Do all public stuff
71+
let _ = ftp_stream.quit();
72+
```
73+
"##
74+
)]
6875
#[macro_use]
6976
extern crate lazy_static;
7077
extern crate chrono;

0 commit comments

Comments
 (0)