Skip to content

The book contradicts itself on returning Box pointers #22610

Closed
@theemathas

Description

@theemathas

From http://doc.rust-lang.org/nightly/book/pointers.html#best-practices-1:

Best practices

Boxes are appropriate to use in two situations: Recursive data structures, and occasionally, when returning data.

However, the book doesn't explain when is it appropriate to return Boxes and even suggests that one should never return Box pointers in http://doc.rust-lang.org/nightly/book/pointers.html#returning-data:

Returning data

This is important enough to have its own section entirely. The TL;DR is this: you don't generally want to return pointers, even when you might in a language like C or C++.

This caused confusion for me whether there really is a reason to return Boxes. Even if there is, I was clueless on what it might be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions