rust - Can I create private enum constructors? -
I can do something like this in Haskell (customized by example)
module size ( Shape, new vinegar, new look, ... - other work to manipulate shapes) data = shape = circle int float - x, y, radius | Rectangle int int int - x1, y1, x2, y2 newCircle :: float - & gt; Shape newCircle r = circle 0 0r newRectangle :: int - & gt; Int - & gt; Size newRectangle WH = rectangle 0 0 wh ... - Other functions for manipulating the shapes This should only me size type and newer / Code> and newRectangle functions.
Is the war equal to this?
In the general sense, no; There is no private NM constructor in Jung, the anom is completely public things.
However, enhancements are not so, and therefore you can add variants to create an implementation statement completely:
// This type did not make anywhere public So it is hidden Enum ShapeInner {// Oh, and let's use struct forms because they are cool {x: i32, y: i32, radius: f64,}, rectangle {x1: i32, y1} : I32, x2: i32, y2: i32,}}} By default, the Structures field is private, so it is hidden. Pub Start ShapeInner; Preventive size {Pub FN Nuclear (Radius: F64) - & gt; Size {shape (circle {x: 0, y: 0, radius: radius})} pub fen new_stangle (width: i32, height: i32) - & gt; Size {shape (x1: 0, y1: 0, x2: width, y2: height})} "match itself {0 circle {..} => ..., ...}", & Amp; c} I would advise against it as a general practice,
Comments
Post a Comment