小编yag*_*eek的帖子

如何在Rust中获得一片Vec <T>?

我在文档中找不到Vec<T>如何从指定范围中检索切片.

标准库中是否有类似的东西:

let a = vec![1, 2, 3, 4];
let suba = a.subvector(0, 2); // Contains [1, 2];
Run Code Online (Sandbox Code Playgroud)

vector rust

31
推荐指数
2
解决办法
2万
查看次数

使用nil指针定义的类型反射创建一个新结构

我想知道是否可以nil通过使用从指针指定的类型分配结构reflect.New()

type SomeType struct{
   A int
}

sometype := (*SomeType)(nil)

v := reflect.valueOf(sometype)
// I would like to allocate a new struct based on the type defined by the pointer
// newA := reflect.New(...)
//
newA.A = 3
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

reflection go

8
推荐指数
1
解决办法
2261
查看次数

Xcode 9.3并更新到High Sierra:即使在完全重新安装后,Instruments也无法打开*.tracetemplate文件

随着在High Sierra上运行Xcode的最后一次更新到9.3,我意识到它Instruments已不再适用了.

当我尝试使用Xcode内部打开它时Open Developer Tool > Instruments,我可以看到模板选择器对话框,但是一旦我选择了一个,就会出现一个对话框:

The document "Allocations.tracetemplate" could not be opened. Instruments cannot open files of this type.
Run Code Online (Sandbox Code Playgroud)

Allocations.tracetemplate 无法处理,因为Instruments无法打开此类文件.

所有模板都会发生这种情况

我已经尝试完全重新安装Xcode.在删除所有文件之前,如下所述:如何完全卸载Xcode并清除所有设置

我还尝试使用sudo chmod a + rwxt /Library/Caches/com.apple.dt.instruments(Xcode 6.3.2:Instruments一直要求跟踪模板?)但是我的计算机上不存在这个文件.

我还安装了Xcode 9.4 beta 1,但这也没有解决问题.

我也无法在我的计算机上找到像Allocations.tracetemplate这样的模板文件.

任何帮助将非常感激;-)

xcode instruments reinstall ios

5
推荐指数
1
解决办法
1284
查看次数

将C本机方法添加到预先存在的Ruby类中

我想知道如何将C扩展中编写的本机方法添加到预先存在的Ruby类中?我只找到了允许你创建新Ruby类的函数,但是没有一个函数可以返回一个预先存在的类.

ruby ruby-c-extension

4
推荐指数
1
解决办法
450
查看次数

与enum和可选元组关联值的Swift模式匹配

我目前正在使用Alamofire,我使用枚举来描述我在自述文件中建议使用的API.

端点表示如下:

public enum API {
    case GetStops(stopCode:String?)
    case GetPhysicalStops
    case GetLinesColors
    case GetNextDepartures(stopCode:String, departureCode:String?, linesCode:String?, destinationsCode:String?)
}
Run Code Online (Sandbox Code Playgroud)

可选参数是互斥的:

 public var URLRequest: NSMutableURLRequest {

        let result:(path:String, parameters:[String:AnyObject]?) = {
            switch self {
            case .GetStops(let stopCode) where stopCode != nil :
                return ("GetStops.json", ["stopCode" : stopCode!])
            case .GetStops(_):
                return ("GetStops.json", nil)
            case .GetPhysicalStops:
                 return ("GetPhysicalStops.json", nil)
            case .GetLinesColors:
                return ("GetLinesColors",nil)
            case .GetNextDepartures(let stopCode, let departureCode, _, _) where departureCode != nil:
                return ("GetNextDepartures", ["stopCode" : stopCode, "departureCode": departureCode!])
            case .GetNextDepartures(let stopCode, …
Run Code Online (Sandbox Code Playgroud)

enums pattern-matching optional swift

4
推荐指数
1
解决办法
1009
查看次数

指向 Go 中接口的指针

我目前正在阅读https://github.com/codegangsta/inject go 包的源代码,以了解该包的工作原理。

我对文件https://github.com/codegangsta/inject/blob/master/inject.go文件有一些疑问,该文件使用 Go 语言的某些元素,我不理解,并且在文档中找不到准确的解释。

// InterfaceOf dereferences a pointer to an Interface type.
// It panics if value is not an pointer to an interface.

func InterfaceOf(value interface{}) reflect.Type {
        t := reflect.TypeOf(value)

        for t.Kind() == reflect.Ptr {
                t = t.Elem()
        }

        if t.Kind() != reflect.Interface {
                panic("Called inject.InterfaceOf with a value that is not a pointer to an interface. (*MyInterface)(nil)")
        }

        return t
}
Run Code Online (Sandbox Code Playgroud)

我的第一个问题是关于for循环的。为什么它使用带有测试表达式的 for 循环?

第二个与恐慌函数中的消息有关。中提到了“指向接口的指针” (*MyInterface)(nil)。当您检查类型是否实现结构时,我只会在有关“编译时检查结构”的 go 文档中遇到类似的构造:

var …
Run Code Online (Sandbox Code Playgroud)

go

3
推荐指数
1
解决办法
1527
查看次数

Golang - 无法使cookie过期

我目前正在使用Go App Engine SDK,我正在尝试设置/过期Cookie.

设置Cookie没有问题,但是无法在浏览器中使其过期.

该应用程序基于一个negroni实例:

func init() {

    app := negroni.New()
    app.UseHandler(Router())
    http.Handle("/", app)

}
Run Code Online (Sandbox Code Playgroud)

路由器是一个mux实例:

func Router() *mux.Router {

    r := mux.NewRouter()
    subRouter := r.PathPrefix(PATH_PREFIX).Subrouter()

    subRouter.HandleFunc("/sign", LoginHandler)
    subRouter.HandleFunc("/userinfo", UserInfo)
    subRouter.HandleFunc("/logout", Logout)

    return r
}
Run Code Online (Sandbox Code Playgroud)

登录处理程序是基本的:

func LoginHandler(w http.ResponseWriter, r *http.Request) {

    ctx := appengine.NewContext(r)

    u := user.Current(ctx)

    if u == nil {

        url, err := user.LoginURL(ctx, r.URL.String())
        if err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
            return
        }
        w.Header().Set("Location", url)
        w.WriteHeader(http.StatusFound)
        return
    }

    //COOKIE_ID = …
Run Code Online (Sandbox Code Playgroud)

cookies go

3
推荐指数
1
解决办法
2537
查看次数

从struct字段分配变量时"无法移出借来的内容"

我正在学习Rust,我正在与借阅检查员作斗争.

我有一个基本的Point结构.我有一个scale修改点的所有坐标的函数.我想从另一个名为的方法调用此方法convert:

struct AngleUnit;

struct Point {
    x: f32,
    y: f32,
    z: f32,
    unit: AngleUnit,
}

fn factor(_from: AngleUnit, _to: AngleUnit) -> f32 {
    1.0
}

impl Point {
    pub fn new(x: f32, y: f32, z: f32, unit: AngleUnit) -> Point {
        Point { x, y, z, unit }
    }

    fn scale(&mut self, factor: f32) {
        self.x *= factor;
        self.y *= factor;
        self.z *= factor;
    }

    fn convert(&mut self, unit: AngleUnit) {
        let point_unit …
Run Code Online (Sandbox Code Playgroud)

rust borrow-checker borrowing

3
推荐指数
1
解决办法
1197
查看次数

是否有文件证明Cargo可以下载并捆绑同一板条箱的多个版本?

通过分叉并使用一些代码,我注意到Cargo可以在同一项目中下载并捆绑同一板条箱的多个版本(例如,native-tls 0.1.5和0.2.1)。通过查看错误版本的文档,我浪费了很多时间。

我一直在寻找有关此行为的一些信息,但找不到任何东西。这是在某处记录的吗?

有没有一种简单的方法来确定/检测您正在使用的代码(当前编辑的文件)所使用的版本?还是如果需要两个版本相同的板条箱,我们可以告诉Cargo显示一些警告/防止构建吗?

rust rust-cargo

3
推荐指数
1
解决办法
422
查看次数

Swift Xcode6B3 - 字节交换 - 未定义的符号"__OSSwapInt16"

我想使用Swift方法,CFSwapInt16BigToHost但我无法将其链接起来.我链接CoreFoundation框架,但每次我收到以下错误:

Undefined symbols for architecture i386:
  "__OSSwapInt16", referenced from:
Run Code Online (Sandbox Code Playgroud)

我错过了什么 ?

xcode linker swift

2
推荐指数
1
解决办法
2101
查看次数

在批量更新删除时禁用NSFetchedResultsController生成的动画

我目前正在使用NSFetchedResultsController来显示UITableView实例中的内容.

在某些时候,我进行批量删除,然后在Core Data中进行批量插入.结果,NSFetchedResultsControllerDelegate逐个进行插入和删除.这给了GUI一个奇怪的外观,你可以逐字地看到这些行被删除或插入.

是否可以在一次中清除或插入一批行而不是迭代地执行NSFetchedResultsControllerDelegate?

animation nsfetchedresultscontroller ios

2
推荐指数
1
解决办法
643
查看次数

struct_ 前缀与无前缀

我目前正在编写一些基本的 cgo 代码。根据关于 Go to C 参考cgo 文档

要直接访问 struct、union 或 enum 类型,请在其前面加上 struct_、union_ 或 enum_ 前缀,如 C.struct_stat 中所示。

我对这句话的理解是,如果我有一个Foo用 C命名的结构体,我必须使用C.struct_FooGo 中的类型。

我写了一些 Go 代码,如:

package main

// #cgo LDFLAGS: -lnavilink -lserialport
// #cgo CFLAGS: -I/usr/local/include
// #include<navilink/navilink.h>
import "C"
import "errors"

func (d *Device) navilinkErrorToGoError() error {
    errorC := C.navilink_get_error_description(d.navilinkC)
    return errors.New(C.GoString(errorC))
    return nil
}

// Device représente une interface
// vers le port série connecté au GPS
type Device struct …
Run Code Online (Sandbox Code Playgroud)

c compilation go cgo

2
推荐指数
1
解决办法
255
查看次数

在两个NSOperations之间传递数据

我非常关注WWDC 2015关于高级NSOperations的会议,我对示例代码进行了一些介绍.

提供的抽象真的很棒,但有些东西我可能并不太了解.

我想在不使用MOC的情况下在两个后续的Operation子类之间传递结果数据.

想象一下,我有一个APIQueryOperation具有NSData?属性和第二操作ParseJSONOperation费时此属性.我如何为NSData?第二次操作提供这种意图?

我试过这样的事情:

queryOperation = APIQueryOperation(request: registerAPICall)  
parseOperation = ParseJSONOperation(data: queryOperation.responseData)  
parseOperation.addDependency(queryOperation) 
Run Code Online (Sandbox Code Playgroud)

但是当我输入实例的execute方法时ParseJSONOperation,与初始化器中的方法不同.

我做错了什么 ?

nsoperation swift

1
推荐指数
1
解决办法
1275
查看次数