lib.rs 10.9 KB
Newer Older
G
Guillaume Gomez 已提交
1 2
//! The point of this crate is to be able to have enough different "kinds" of
//! documentation generated so we can test each different features.
3
#![doc(html_playground_url="https://play.rust-lang.org/")]
G
Guillaume Gomez 已提交
4 5

#![crate_name = "test_docs"]
N
Nilstrieb 已提交
6
#![allow(internal_features)]
7
#![feature(rustdoc_internals)]
8
#![feature(doc_cfg)]
9
#![feature(associated_type_defaults)]
G
Guillaume Gomez 已提交
10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
this crate even more!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
this crate even more!
Enable the feature <span class="stab portability"><code>some-feature</code></span> to enjoy
this crate even more!

Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.
Also, stop using `bar` as it's <span class="stab deprecated" title="">deprecated</span>.

Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
</span>.
Finally, you can use `quz` only on <span class="stab portability"><code>Unix or x86-64</code>
</span>.
*/

29
use std::convert::AsRef;
G
Guillaume Gomez 已提交
30 31 32 33 34 35
use std::fmt;

/// Basic function with some code examples:
///
/// ```
/// println!("nothing fancy");
G
Guillaume Gomez 已提交
36
/// println!("but with two lines!");
G
Guillaume Gomez 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49
/// ```
///
/// A failing to compile one:
///
/// ```compile_fail
/// println!("where did my argument {} go? :'(");
/// ```
///
/// An ignored one:
///
/// ```ignore (it's a test)
/// Let's say I'm just some text will ya?
/// ```
50
///
G
Guillaume Gomez 已提交
51 52 53 54 55 56
/// A failing to run one:
///
/// ```should_panic
/// panic!("tadam");
/// ```
///
57
/// An inlined `code`!
G
Guillaume Gomez 已提交
58 59 60 61 62
pub fn foo() {}

/// Just a normal struct.
pub struct Foo;

63 64
impl Foo {
    #[must_use]
A
Arpad Borsos 已提交
65 66 67
    pub fn must_use(&self) -> bool {
        true
    }
68 69 70 71 72 73 74 75 76 77 78 79

    /// hello
    ///
    /// <div id="doc-warning-1" class="warning">this is a warning</div>
    ///
    /// done
    pub fn warning1() {}

    /// Checking there is no bottom margin if "warning" is the last element.
    ///
    /// <div id="doc-warning-2" class="warning">this is a warning</div>
    pub fn warning2() {}
80 81
}

82 83 84 85 86 87
impl AsRef<str> for Foo {
    fn as_ref(&self) -> &str {
        "hello"
    }
}

G
Guillaume Gomez 已提交
88
/// Just a normal enum.
89 90
///
/// # title!
91
#[doc(alias = "ThisIsAnAlias")]
92
#[non_exhaustive]
G
Guillaume Gomez 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105 106
pub enum WhoLetTheDogOut {
    /// Woof!
    Woof,
    /// Meoooooooow...
    Meow,
}

/// Who doesn't love to wrap a `format!` call?
pub fn some_more_function<T: fmt::Debug>(t: &T) -> String {
    format!("{:?}", t)
}

/// Woohoo! A trait!
pub trait AnotherOne {
107 108 109
    /// Some func 3.
    fn func3();

G
Guillaume Gomez 已提交
110 111 112
    /// Some func 1.
    fn func1();

113 114 115
    fn another();
    fn why_not();

G
Guillaume Gomez 已提交
116 117 118
    /// Some func 2.
    fn func2();

119
    fn hello();
G
Guillaume Gomez 已提交
120 121
}

122 123 124 125
/// ```compile_fail
/// whatever
/// ```
///
G
Guillaume Gomez 已提交
126 127 128
/// Check for "i" signs in lists!
///
/// 1. elem 1
129 130 131 132
/// 2. test 1
///    ```compile_fail
///    fn foo() {}
///    ```
G
Guillaume Gomez 已提交
133 134 135 136 137
/// 3. elem 3
/// 4. ```ignore (it's a test)
///    fn foo() {}
///    ```
/// 5. elem 5
138 139 140 141 142 143
///
/// Final one:
///
/// ```ignore (still a test)
/// let x = 12;
/// ```
G
Guillaume Gomez 已提交
144
pub fn check_list_code_block() {}
A
Arpad Borsos 已提交
145

146 147 148 149 150
/// a thing with a label
#[deprecated(since = "1.0.0", note = "text why this deprecated")]
#[doc(cfg(unix))]
pub fn replaced_function() {}

151
/// Some doc with `code`!
A
Arpad Borsos 已提交
152 153 154
pub enum AnEnum {
    WithVariants { and: usize, sub: usize, variants: usize },
}
155 156

#[doc(keyword = "CookieMonster")]
157
/// Some keyword.
158
pub mod keyword {}
159 160 161

/// Just some type alias.
pub type SomeType = u32;
162 163 164 165

pub mod huge_amount_of_consts {
    include!(concat!(env!("OUT_DIR"), "/huge_amount_of_consts.rs"));
}
166 167 168

/// Very long code text `hereIgoWithLongTextBecauseWhyNotAndWhyWouldntI`.
pub mod long_code_block {}
169

170 171 172 173 174
/// Very long code text [`hereIgoWithLongTextBecauseWhyNotAndWhyWouldntI`][lnk].
///
/// [lnk]: crate::long_code_block_link
pub mod long_code_block_link {}

175 176 177 178 179 180
#[macro_export]
macro_rules! repro {
    () => {};
}

pub use crate::repro as repro2;
181 182 183 184 185 186 187 188 189 190 191 192

/// # Top-doc Prose title
///
/// Text below title.
///
/// ## Top-doc Prose sub-heading
///
/// Text below sub-heading.
///
/// ### Top-doc Prose sub-sub-heading
///
/// Text below sub-sub-heading
193 194 195 196
///
/// #### You know the drill.
///
/// More text.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
pub struct HeavilyDocumentedStruct {
    /// # Title for field
    /// ## Sub-heading for field
    pub nothing: (),
}

/// # Title for struct impl doc
///
/// Text below heading.
///
/// ## Sub-heading for struct impl doc
///
/// Text below sub-heading.
///
/// ### Sub-sub-heading for struct impl doc
///
/// Text below sub-sub-heading.
///
impl HeavilyDocumentedStruct {
    /// # Title for struct impl-item doc
    /// Text below title.
    /// ## Sub-heading for struct impl-item doc
    /// Text below sub-heading.
    /// ### Sub-sub-heading for struct impl-item doc
    /// Text below sub-sub-heading.
    pub fn do_nothing() {}
}

/// # Top-doc Prose title
///
/// Text below title.
///
/// ## Top-doc Prose sub-heading
///
/// Text below sub-heading.
///
/// ### Top-doc Prose sub-sub-heading
///
/// Text below sub-sub-heading
pub enum HeavilyDocumentedEnum {
    /// # None prose title
    /// ## None prose sub-heading
    None,
    /// # Wrapped prose title
    /// ## Wrapped prose sub-heading
    Wrapped(
        /// # Wrapped.0 prose title
        /// ## Wrapped.0 prose sub-heading
        String,
        String,
    ),
    Structy {
        /// # Structy prose title
        /// ## Structy prose sub-heading
        alpha: String,
        beta: String,
    },
}

/// # Title for enum impl doc
///
/// Text below heading.
///
/// ## Sub-heading for enum impl doc
///
/// Text below sub-heading.
///
/// ### Sub-sub-heading for enum impl doc
///
/// Text below sub-sub-heading.
///
impl HeavilyDocumentedEnum {
    /// # Title for enum impl-item doc
    /// Text below title.
    /// ## Sub-heading for enum impl-item doc
    /// Text below sub-heading.
    /// ### Sub-sub-heading for enum impl-item doc
    /// Text below sub-sub-heading.
    pub fn do_nothing() {}
}

/// # Top-doc prose title
///
/// Text below heading.
///
/// ## Top-doc prose sub-heading
///
/// Text below heading.
pub union HeavilyDocumentedUnion {
    /// # Title for union variant
    /// ## Sub-heading for union variant
    pub nothing: (),
    pub something: f32,
}

/// # Title for union impl doc
/// ## Sub-heading for union impl doc
impl HeavilyDocumentedUnion {
    /// # Title for union impl-item doc
    /// ## Sub-heading for union impl-item doc
    pub fn do_nothing() {}
}

/// # Top-doc prose title
///
/// Text below heading.
///
/// ## Top-doc prose sub-heading
///
/// Text below heading.
#[macro_export]
macro_rules! heavily_documented_macro {
    () => {};
}
311 312 313 314 315 316 317 318 319 320 321

pub trait EmptyTrait1 {}
pub trait EmptyTrait2 {}
pub trait EmptyTrait3 {}

pub struct HasEmptyTraits{}

impl EmptyTrait1 for HasEmptyTraits {}
impl EmptyTrait2 for HasEmptyTraits {}
#[doc(cfg(feature = "some-feature"))]
impl EmptyTrait3 for HasEmptyTraits {}
322 323 324

mod macros;
pub use macros::*;
325 326 327

#[doc(alias = "AliasForTheStdReexport")]
pub use ::std as TheStdReexport;
328 329 330 331 332 333 334 335 336 337 338

pub mod details {
    /// We check the appearance of the `<details>`/`<summary>` in here.
    ///
    /// ## Hello
    ///
    /// <details>
    /// <summary><h4>I'm a summary</h4></summary>
    /// <div>I'm the content of the details!</div>
    /// </details>
    pub struct Details;
339 340 341 342 343 344 345 346 347 348 349 350

    impl Details {
        /// We check the appearance of the `<details>`/`<summary>` in here.
        ///
        /// ## Hello
        ///
        /// <details>
        /// <summary><h4>I'm a summary</h4></summary>
        /// <div>I'm the content of the details!</div>
        /// </details>
        pub fn method() {}
    }
351
}
352 353 354 355

pub mod doc_block_table {

    pub trait DocBlockTableTrait {
356
        fn foo();
357 358 359 360 361 362 363
    }

    /// Struct doc.
    ///
    /// | header1                  | header2                  |
    /// |--------------------------|--------------------------|
    /// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
364 365 366
    /// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
    /// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
    /// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
367 368 369 370 371 372 373 374
    pub struct DocBlockTable {}

    impl DocBlockTableTrait for DocBlockTable {
        /// Trait impl func doc for struct.
        ///
        /// | header1                  | header2                  |
        /// |--------------------------|--------------------------|
        /// | Lorem Ipsum, Lorem Ipsum | Lorem Ipsum, Lorem Ipsum |
375
        fn foo() {
376 377 378 379 380
            println!();
        }
    }

}
381 382 383 384 385 386 387 388 389 390 391 392

pub struct NotableStructWithLongName<R>(R);

impl<R: std::io::Read> NotableStructWithLongName<R> {
    pub fn create_an_iterator_from_read(r: R) -> NotableStructWithLongName<R> { Self(r) }
}

impl<R: std::io::Read> std::iter::Iterator for NotableStructWithLongName<R> {
    type Item = ();

    fn next(&mut self) -> Option<Self::Item> { () }
}
393 394 395 396 397 398 399 400

pub trait TraitWithNoDocblocks {
    fn first_fn(&self);
    fn second_fn(&self);
}

pub struct TypeWithNoDocblocks;

401 402 403 404 405 406 407 408 409 410 411
impl TypeWithNoDocblocks {
    fn x() -> Option<Self> {
        Some(Self)
    }
    fn y() -> Option<u32> {
        // code comment
        let t = Self::x()?;
        Some(0)
    }
}

412 413
impl TypeWithNoDocblocks {
    pub fn first_fn(&self) {}
414 415 416 417 418
    pub fn second_fn<'a>(&'a self) {
        let x = 12;
        let y = "a";
        let z = false;
    }
419
}
420 421 422 423

pub unsafe fn unsafe_fn() {}

pub fn safe_fn() {}
424 425 426 427 428 429 430 431 432

#[repr(C)]
pub struct WithGenerics<T: TraitWithNoDocblocks, S = String, E = WhoLetTheDogOut, P = i8> {
    s: S,
    t: T,
    e: E,
    p: P,
}

433 434 435 436 437
pub struct StructWithPublicUndocumentedFields {
    pub first: u32,
    pub second: u32,
}

438 439 440 441 442 443 444 445
pub const CONST: u8 = 0;

pub trait TraitWithoutGenerics {
    const C: u8 = CONST;
    type T = SomeType;

    fn foo();
}
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462

pub mod trait_members {
    pub trait TraitMembers {
        /// Some type
        type Type;
        /// Some function
        fn function();
        /// Some other function
        fn function2();
    }
    pub struct HasTrait;
    impl TraitMembers for HasTrait {
        type Type = u8;
        fn function() {}
        fn function2() {}
    }
}
463 464 465 466 467 468 469 470

pub struct TypeWithImplDoc;

/// impl doc
impl TypeWithImplDoc {
    /// fn doc
    pub fn test_fn() {}
}
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489

/// <sub id="codeblock-sub-1">
///
/// ```
/// one
/// ```
///
/// </sub>
///
/// <sub id="codeblock-sub-3">
///
/// ```
/// one
/// two
/// three
/// ```
///
/// </sub>
pub mod codeblock_sub {}
490 491 492 493 494 495 496 497 498 499 500 501
pub mod search_results {

    pub struct SearchResults {
        pub foo: i32,
    }

    #[macro_export]
    macro_rules! foo {
        () => {};
    }

}
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522

pub mod fields {
    pub struct Struct {
        pub a: u8,
        pub b: u32,
    }
    pub union Union {
        pub a: u8,
        pub b: u32,
    }
    pub enum Enum {
        A {
            a: u8,
            b: u32,
        },
        B {
            a: u8,
            b: u32,
        },
    }
}
523 524 525 526 527 528 529 530 531

pub mod cfgs {
    #[doc(cfg(all(
        any(not(feature = "appservice-api-c"), not(feature = "appservice-api-s")),
        any(not(feature = "client"), not(feature = "server")),
    )))]
    /// Some docs.
    pub mod cfgs {}
}