Skip to content

Conversation

@kingwingfly
Copy link
Contributor

Objective

fixes #42

It also supports fake variadic when length 1 not included.

Solution

Instead of n == 1 to judge if it's the first one, I tried n == input.start.max(1). This ensure that the first tuples will always have attributes. So that length 1 does not need including.

let doc = LitStr::new(
                    &format!(
                        "This trait is implemented for tuples **{down}up to {up}** items long.",
                        down = if input.start != 0 {
                            format!("down to {} ", input.start)
                        } else {
                            "".to_string()
                        },
                        up = input.end
                    ),
                    Span2::call_site(),
                );

And omit document like down to 0.

Testing

I checked with this command:

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --example all_tuples --no-deps --open

And

all_tuples!(
    #[doc(fake_variadic)]
    impl_tuple_foo,
    0,
    15,
    F
);

all_tuples!(
    #[doc(fake_variadic)]
    impl_tuple_foo,
    1,
    15,
    F
);

all_tuples!(
    #[doc(fake_variadic)]
    impl_tuple_foo,
    3,
    15,
    F
);

works as expected.

I also passed cargo test

@BenjaminBrienen
Copy link
Collaborator

Can you include a screenshot of the generated documentation so that I can see it working?

@kingwingfly
Copy link
Contributor Author

Instead of n == 1 to judge if it's the first one, I tried n == input.start.max(1). This ensure that the first tuples will always have attributes. So that length 1 does not need including.

I just fixed some bugs... And the previous solution is wrong...

However, the new version is tested below:

all_tuples!(
    #[doc(fake_variadic)]
    impl_tuple_foo,
    0,
    5,
    F
);
image
all_tuples!(
    #[doc(fake_variadic)]
    impl_tuple_foo,
    1,
    5,
    F
);
image
all_tuples!(
    #[doc(fake_variadic)]
    impl_tuple_foo,
    3,
    5,
    F
);
image

cargo +nightly expand --example all_tuples (no implementation for (F, ))

image

RUSTFLAGS="--cfg docsrs" cargo +nightly expand --example all_tuples (only with --cfg docsrs, there's implementation for (F, ))

image
all_tuples!(impl_tuple_foo, 1, 5, F);
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong tuple lengths being documented.

2 participants