Getting a pointer to an immutable structure

I am writing a wrapper for some C library. Can I use UnsafePointer for an immutable structure? For mutable structures, this is 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 perfect.

+4
source share

All Articles