5

I'm writing wrapper for some C library. Is it possible to take UnsafePointer to immutable struct? For mutable structs it's not a problem:

func Foo_get(ptr : UnsafePointer<Foo>) {
    //does not mutate
}

struct Foo {
    //big data

    mutating func get1() { //inconvenient
        Foo_get(&self)
    }

    func get2() { //unnecessary copy
        var copy = self
        Foo_get(&copy)
    }
}

But both of these solutions are not ideal.

szotp
  • 2,472
  • 1
  • 18
  • 21

0 Answers0