How to import package "constraints" in Go?

huangapple go评论72阅读模式
英文:

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 :

https://go.dev/tour/

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

huangapple
  • 本文由 发表于 2023年3月14日 17:37:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75731343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定