Dart库vs lib(Dart library vs lib)

编程入门 行业动态 更新时间:2024-10-24 04:35:09
Dart库vs lib(Dart library vs lib)

在Dart-land中, library声明和项目中的lib目录之间的关系是什么? 换句话说,如果我的项目有这样的结构:

myapp/ lib/ SomeType.dart src/ SomeOtherType.dart web/ AnotherType.dart another-type.html

在SomeType.dart我有:

library myapp.logging;

class SomeType {
    // ...
}
 

...那么myapp/lib目录和Dart源代码中散布的任何 library声明之间的区别是什么?

In Dart-land, what is the relationship between a library declaration and the lib directory inside the project? In other words, if my project has a structure like this:

myapp/ lib/ SomeType.dart src/ SomeOtherType.dart web/ AnotherType.dart another-type.html

And in SomeType.dart I have:

library myapp.logging;

class SomeType {
    // ...
}
 

...then what's the difference between the myapp/lib directory and any library declarations sprinkled throughout the Dart source code?

最满意答案

最终,您的目录结构与Dart中的库关键字之间没有任何关系。

dart目录结构来自推荐的包布局约定,但不以任何方式强制使用该语言。 只有在尝试使用pub包管理器将包发布(上载)到官方dart存储库时,才会强制执行它们。 最终,您可以使用您选择的任何目录结构布局。 建议使用此程序包以保持程序包之间的一致性,特别是对于可能具有其他外部贡献者的开源程序包或应用程序。

Dart中的library关键字以命名空间的方式使用。 例如,下划线私有变量仅具有库可见性。 同一个库中的任何内容都可以查看/访问您的下划线变量。 除了它之外的任何东西都不能。 您可以使用关键字的part和part of使其他文件成为库的一部分(无论它们在目录结构中的位置如何)。

Ultimately, there is no relation between your directory structure and the library keyword in Dart.

The dart directory structure comes from the recommended package layout conventions but are not enforced by the language in any way. They are only enforced if you try to use the pub package manager to publish (upload) your package to the official dart repository. Ultimately you can use whatever directory structure layout you choose. This one is recommended to keep consistency between packages, particularly for Open Source packages or applications which may have other external contributors.

The library keyword in Dart is used in a way of namespacing. For instance the underscore private variables are only have library visibility. Anything in the same library can see/access your underscore variables. Anything outside of it cannot. You can use the part and part of keywords to make other files part of a library (regardless of where they are located in the directory structure).

更多推荐

本文发布于:2023-08-06 04:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444435.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Dart   lib   library

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!