ParseBoolError
为什么有const src = {
cash: true,
cashless: true,
credit: [],
gift: true,
stamp: true,
stamp_number: 10,
stamp_reward: "Free tea",
terms_and_conditions: "Terms & Conditions",
tier_type: "visits",
upfront: false
},
result = Object
.keys(src)
.filter(key => ['gift', 'stamp', 'upfront'].includes(key) && src[key] === true)
.map(key => `${key[0].toUpperCase()}${key.slice(1)}`)
.join(', ')
console.log(result)
字段:
_priv
我不认为使用了pub struct ParseBoolError {
_priv: (),
}
字段。
答案 0 :(得分:35)
如果结构具有私有字段,则不能创建该结构的实例。这只是防止在用户代码中构造ParseBoolError
的一种技巧。
这样做的一个原因是为了向前兼容。如果用户可以使用以下方法创建它:
let error = ParseBoolError {};
然后,ParseBoolError
的将来版本无法在不破坏该代码的情况下添加字段。