英文:
How to import package "constraints" in Go?
问题
如果你想学习Go语言,可以参考这个链接:https://go.dev/tour/
你可以尝试使用类似"Ordered"的约束条件。
然而,导入"constraints"会返回一个错误:
package constraints is not in GOROOT
英文:
If you do the tour to learn go here :
You may try to use constraints like Ordered.
However,
import "constraints"
returns an error :
package constraints is not in GOROOT
答案1
得分: 3
"constraints"
包不是标准库的一部分,也从未是过,除非在Go 1.18之前的早期开发或测试版本中可能存在。
正确的导入路径是:
import "golang.org/x/exp/constraints"
与x/exp
中的所有代码一样,它不在Go的兼容性保证范围内。
不将其包含在标准库中的原因在这里提到:https://github.com/golang/go/issues/50792
英文:
The "constraints"
package is not part of the standard library and never was, except perhaps for early dev or beta releases before Go 1.18.
The correct import path is:
import "golang.org/x/exp/constraints"
As all code in x/exp
it's outside of Go compatibility guarantee.
The reason for not including it in the standard library is mentioned here: https://github.com/golang/go/issues/50792
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论