1

Because all references in Rust are typed with &, it's not obvious which of them are fat and which are thin. So the symbol & by itself doesn't tell you the stack representation of an arbitrary reference type. For example, it's not clear that &str is fat but &String is thin until one learns how they are actually implemented.

My question is do we have an exhaustive list of all fat references/pointers so that we can safely regard all those not on the list as thin? (All custom DSTs shall be counted as one category in the above mentioned exhaustive list.)

Edit. Differences from that linked question: Here the answer shall be definitive and able to assert whether &T is fat or thin for any type T, in finite steps.

(We do not consider mutability in this question.)

(Closed not because of a dup but answered in chat.)

TSK
  • 509
  • 1
  • 9
  • 3
    Does this answer your question? [What is a "fat pointer"?](https://stackoverflow.com/questions/57754901/what-is-a-fat-pointer) (Despite the question name, I think the answer covers most or all of what you're asking.) – Dan Getz Nov 10 '22 at 19:55
  • @DanGetz Nope. It doesn't mention "exhaustiveness" and its "currently" means 2019., so that I cannot safely assume any `&T` where `T` is not on their list is thin. What's more, it doesn't answer if users can define custom data types whose references are fat. – TSK Nov 10 '22 at 19:57
  • 3
    @TSK: The top/accepted answer on the duplicate does in fact describe user-defined dynamically sized types that produce fat references (under the heading "Custom DSTs"); as such, there are a potentially infinite number of data types that produce fat references. If there have been updates to the list, new answers should be posted on the canonical dupe, or existing answers updated, but it's quite clear that the list cannot be exhaustive (since users can define new types that make fat references). Your question is fully answered. – ShadowRanger Nov 10 '22 at 20:02
  • 1
    And it describes the fundamental difference that determines if a type's reference is fat: if it's not fixed-size. That might not be literally a "list", but it answers the same sort of question of "which ones are which". – Dan Getz Nov 10 '22 at 20:05
  • @ShadowRanger I think by "exhaustiveness" I mean we put all "Custom DSTs having a struct where the last field is a DST" in one category so that they count as one. About "A reference or pointer to the custom DST is also a fat pointer.": Is it *always* fat pointer? About "The additional data depends on the kind of DST inside the struct.": How exactly are they related? – TSK Nov 10 '22 at 20:10
  • @DanGetz It has yet to assert "the fundamental difference that *determines*..." Can we say a reference is fat *if and only if* its type is not fixed-size? – TSK Nov 10 '22 at 20:15
  • Well, according to that answer it must be fat if it's not fixed size. Is your question "could there be different sizes of thin pointers?" – Dan Getz Nov 10 '22 at 20:22
  • @DanGetz No I'm looking for a decisive process you can follow to assert for any type `T` whether `&T` is fat or thin. The process could look something like this: (if `T` a slice then fat else (if `T` is a struct whose last field is DST then fat else (...(thin)))). I'm asking if this process can be expressed in finite steps. In other words you must give a criteria that generates the correct answer for *any* type `T`. – TSK Nov 10 '22 at 20:27
  • Oh, per that answer, sizedness. You can make a function or type generic over it, even. – Dan Getz Nov 10 '22 at 20:29
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/249495/discussion-between-tsk-and-dan-getz). – TSK Nov 10 '22 at 20:29
  • 2
    This question asks something not covered in the other answer: "assert whether &T is fat or thin for any type T". Since the other answer was written, this has become possible behind the `ptr_metadata` feature flag using the [`Pointee`](https://doc.rust-lang.org/stable/core/ptr/trait.Pointee.html) trait and the alias [`Thin`](https://doc.rust-lang.org/stable/core/ptr/traitalias.Thin.html), equivalent to `Pointee`. A trait bound `T: Thin` guarantees that `&T` is thin. – Mac O'Brien Nov 10 '22 at 20:52
  • 1
    I think it's abundantly clear that this question is wholly different than the question this was marked as a duplicate of. Even if the answer to the other question does provide some insight, that is not sufficient reason to mark this as dup. – user4815162342 Nov 10 '22 at 20:59
  • 2
    @user4815162342: A similar question that produces, by side-effect, a complete answer to a new question is still a valid duplicate target. [Per Meta](https://meta.stackexchange.com/a/12184/322040): "**If you ask a question similar to another question and it is likely to get the exact same answer, you have yourself a duplicate question.**" This question is similar (not the same, but it doesn't need to be), but it would get the exact same answer already found on that other question. This question shouldn't be deleted (it's a good breadcrumb), but it's already answered there. – ShadowRanger Nov 10 '22 at 21:05
  • 2
    I think that both questions are very close: if you know what the definition of a fat pointer is, then it's easy to figure out whether `&T` is a fat pointer or not. However, with the `Pointee` trait, it is possible that the answer to the other question will "soon" become obsolete. – jthulhu Nov 10 '22 at 21:11

0 Answers0