Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification on style for functions with very long return types #134

Open
davechallis opened this issue Nov 5, 2018 · 1 comment
Open

Comments

@davechallis
Copy link

Might be useful to include some guidance on how to deal with function return types that don't fit on a single line within the recommended line length limit, e.g.:

fn foo(
    &self,
    x: i32,
    y: i32
) -> fn(a: SomeLongComplexType, b: SomeOtherLongComplexType) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>> {
    ...
}

E.g. is it preferred to keep on a single line as in the example above? Or should it be split along similar lines to the outer function, i.e.

fn foo(
    &self,
    x: i32,
    y: i32
) -> fn(
    a: SomeLongComplexType,
    b: SomeOtherLongComplexType
) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>> {
    ...
}
@joshtriplett
Copy link
Member

Ouch. Good example, and that seems painful for several reasons, not least of which making it easy to confuse the two function-syntax types and the return type.

As far as I can tell, we don't have any guidance for when the return type is too long to fit on one line.

I would personally be inclined to write that this way:

fn foo(
    &self,
    x: i32,
    y: i32
) ->
    fn(
        a: SomeLongComplexType,
        b: SomeOtherLongComplexType
    ) -> Box<Future<Item = AnotherLongType, Error = ALongErrorType>>
{
    ...
}

I also don't mind writing the fn( on the same line as the ) ->, but I'd prefer to add extra indentation on the return-type function-type arguments and on its return type, and then not put the { on the same line.

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

No branches or pull requests

2 participants