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

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems quite reasonable and I'd like to fix this.

Can you add some tests to the library itself to ensure that this keeps working?

@kingwingfly
Copy link
Contributor Author

I do not know how to verify documentation generated by cargo-doc right now.

Anyway, I will try in a few days. (I'm preparing my final exam and am very busy at this moment.)

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.

3 participants